// UhfReaderDlg.cpp : implementation file
//

#include "stdafx.h"
#include "UhfReader.h"
#include "UhfReaderDlg.h"
#include "UhfReadApi.h"
#include "EnumSerial.h"
#include "readerapi.h"
#include <winsock2.h>

#pragma comment(lib, "ws2_32.lib")

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

BYTE IDBuffer[30*256] = {0};
int giTimes = 0;


#define MODE_ALLWAYS_READ 1
#define MODE_TRIGGER_READ 0


unsigned char GlAddresss=0xff;

unsigned char GlReaderType;
unsigned char GlComMode;

CString STRING_SAVED;
CString STRING_SUCCESS;
CString STRING_CONFIGURE_FAIL;
CString STRING_CONNECT_FAIL;
CString STRING_CONNECT_SUCCESFUL;
CString STRING_DISCONNECTED;
CString STRING_GET_OUTPOWER_FAIL;
CString STRING_GET_WIEGAND_OUTPUT_SETTINGS_FAIL;
CString STRING_SET_WIEGAND_OUTPUT_SETTINGS_FAIL;
CString STRING_WIEGAND_OUTPUT_SETTINGS;

CString STRING_GET_FREQUENCY_REGION_FAIL;
CString STRING_GET_ADDRESS_FAIL;
CString STRING_READ_CONFIGURATION_OK;
CString STRING_SET_OUTPOWER_FAIL;
CString STRING_SET_FREQUENCY_REGION_FAIL;
CString STRING_SET_ADDRESS_FAIL;

CString STRING_FREQ_ERROR;
CString STRING_LENGHT_BYTES_PARAMETER_ERROR;
CString STRING_START_BYTES_PARAMETER_ERROR;
CString STRING_READ_TIME_PARAMETER_ERROR;
CString STRING_OUTPUT_TIME_PARAMETER_ERROR;
CString STRING_POWER_PARAMETER_ERROR;
CString STRING_DELETE;
CString STRING_WARNNING;
CString STRING_PARAMETER_ERROR;



CString IntToChar(int InData);

static unsigned char Uhf_CheckSum(unsigned char *uBuff, unsigned char uBuffLen)
{
	unsigned char i,uSum=0;
	for(i=0;i<uBuffLen;i++)
	{
		uSum = uSum + uBuff[i];
	}
	uSum = (~uSum) + 1;
	return uSum;
}

static int Byte2HexChar(BYTE *bData, int iLen, char *data)
{
	int ii = 0, jj = 0;
	for (ii = 0; ii < iLen; ii++, jj+=2)
	{
		sprintf(&data[jj], "%02x", bData[ii]);
	}
	data[jj] = 0;
	return 0;
}

static char ConvertHexChar(char ch) 
{       
	if( (ch>='0') && (ch<='9') ){
		return ch-0x30;
	}else if( (ch>='A') && (ch<='F') ){
		return ch-'A'+10;
	}else if( (ch>='a') && (ch<='f') ){
		return ch-'a'+10;
	}else{
		return (-1);
	}
}


static int String2Hex(const char *strData, BYTE *senddata)
{
	int hexdata,lowhexdata;
	int hexdatalen=0;
	int len;
    int i;
    char lstr,hstr;
	char str[1024] = {0};
	len = strlen(strData);
	int kk = 0;
	
	for (i = 0; i < len; i++)
	{
		if (strData[i] != ' ')
		{
			str[kk++] = strData[i];
		}
	}
	
	//senddata.SetSize(len/2);
	if( len > 1024 ){
        return 0; 
	}
	for( i=0; i<len; ){
		hstr = str[i];
		if( hstr==' ' ){
			i++;
			continue;
		}
		i++;
		if( i>=len ){
			break;
		}
		lstr = str[i];
		hexdata    = ConvertHexChar(hstr);
		lowhexdata = ConvertHexChar(lstr);
		if( (hexdata == -1) || (lowhexdata == -1) ){
			break;
		}else{ 
			hexdata=(hexdata<<4) | lowhexdata;
		}
		i++;
		senddata[hexdatalen++]=(char)hexdata;
	}
	//senddata.SetSize(hexdatalen);
	return hexdatalen;
}

CString IntToChar(int InData)
{
	int i;
	int outdata=0,num=0;
	CString strTmp;

	num=1;
	if(InData>9)num=2;
	if(InData>99)num=3;
	strTmp="";
	switch(num)
	{
	case 1:
		strTmp.Format("%01d",InData);
		break;

	case 2:
		strTmp.Format("%02d",InData);
		break;
	case 3:
		strTmp.Format("%03d",InData);
		break;
	default:break;

	}
	return strTmp;

}



static int CharToInt(char *InData)
{
	int i;
	int outdata=0,num=0;
	for(i=0;i<3;i++)
	{
		if(InData[i]==0)break;
	}
	num=i;
	switch(num)
	{
		case 0 :
			outdata	=0;
			break;
	
		case 1 :
				outdata	=InData[0]-0x30;
				break;
		case 2 :
				outdata	=(InData[0]-0x30)*10+InData[1]-0x30;
			break;
		case 3 :
				outdata	=(InData[0]-0x30)*100+(InData[1]-0x30)*10+InData[2]-0x30;
			break;
		default: break;
	}

	
	return outdata;
}




static int Hex2Char(BYTE *bData, char *szData, int iLen)
{
	int ii, jj;
	for (ii = 0, jj = 0; ii < iLen; ii++, jj += 2)
	{
		sprintf(&szData[jj], "%02X ", bData[ii]);
	}
	szData[jj] = 0;
	return 0;
}

/***********************************************************
** 函数名称: CString IntToASCII(unsigned char input)
** 功能描述: 将两位的无符号整数转换为字符串
** 输　  入:   unsigned char input : 16进制数
** 输    出:   input  的字符串形式  

  ** 例    如： 0xFF - > "FF" 
************************************************************/
CString IntToASCII(unsigned char input)
{
	char temp[2];
	char exchange;
	CString output = "";		
	itoa(input,temp,16);		//结果高位放于temp[0],低位放于temp[1]
	if (temp[1] == 0)	        //因为如果input为0x0F 时，结果为 'F','0';	
	{						    //所以要交换一下temp[1]与temp[0]
		exchange = temp[1];
		temp[1]  = temp[0];
		temp[0]  = exchange;
	}	
	if (temp[0] == 0)  output += "0";
	   else	           output += temp[0];
	   
	   if (temp[1] == 0)  output += "0";
	   else            output += temp[1];
	   return output;
}



/////////////////////////////////////////////////////////////////////////////
// CUhfReaderDlg dialog

CUhfReaderDlg::CUhfReaderDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CUhfReaderDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CUhfReaderDlg)
	m_status_display = _T("");
	m_password = _T("00000000");
	m_readcard_delaytime = 5;
	m_OutPowerValue = 0;
	m_wg_time = 2;
	m_address = 0;
	m_trigger_time = 1;
	m_version = _T("");
	m_host_port = 2000;
	m_reader_port = 27001;
	m_sernum = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_IsOpen = FALSE;

	m_hEpccEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

	m_iAutoReadFlag = FALSE;
	m_IsExitReadEPC = FALSE;
}

void CUhfReaderDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CUhfReaderDlg)
	DDX_Control(pDX, IDC_COMBO_START_BYTE, m_start_byte);
	DDX_Control(pDX, IDC_COMBO_OUT_LEN, m_out_len);
	DDX_Control(pDX, IDC_IPADDRESS_READER, m_reader_ip);
	DDX_Control(pDX, IDC_IPADDRESS_HOST, m_host_ip);
	DDX_Control(pDX, IDC_COMBO_POWER, m_power);
	DDX_Control(pDX, IDC_COMBO_START_RF, m_start_rf);
	DDX_Control(pDX, DC_COMBO_END_RF, m_end_rf);
	DDX_Control(pDX, IDC_BTN_CONNECT, m_connect);
	DDX_Control(pDX, IDC_BTN_CLOSEPORT, m_disconnect);
	DDX_Control(pDX, IDC_READ_CONFIG, m_readconfig);
	DDX_Control(pDX, IDC_BTN_SETDEFAULT, m_factorydefault);
	DDX_Control(pDX, IDC_BTN_SAVE, m_savechange);
	DDX_Control(pDX, IDC_BTN_READTAG, m_testcard);
	DDX_Control(pDX, IDC_LIST_CG, m_List6cID);
	DDX_Control(pDX, IDC_COMBO_BAUDRATE, m_comboBaud);
	DDX_Control(pDX, IDC_CB_BAUDRATE, m_cbBaud);
	DDX_Control(pDX, IDC_CB_COMPORT, m_cbCom);
	DDX_Text(pDX, IDC_STATUS_DISPLAY, m_status_display);
	DDX_Text(pDX, IDC_EDIT_PASSWORD, m_password);
	DDV_MaxChars(pDX, m_password, 8);
	DDX_Text(pDX, IDC_EDIT_READCARD_DELAYTIME, m_readcard_delaytime);
	DDV_MinMaxUInt(pDX, m_readcard_delaytime, 0, 266);
	DDX_Text(pDX, IDC_EDIT_POWER, m_OutPowerValue);
	DDX_Text(pDX, IDC_EDIT_WG_TIME, m_wg_time);
	DDX_Text(pDX, IDC_EDIT_ADDRESS, m_address);
	DDV_MinMaxByte(pDX, m_address, 0, 255);
	DDX_Text(pDX, IDC_EDIT_TRIGGER_TIME, m_trigger_time);
	DDV_MinMaxByte(pDX, m_trigger_time, 0, 255);
	DDX_Text(pDX, IDC_STATIC_VERSION, m_version);
	DDX_Text(pDX, IDC_EDIT_HOST_PORT, m_host_port);
	DDV_MinMaxUInt(pDX, m_host_port, 0, 65555);
	DDX_Text(pDX, IDC_EDIT_READER_PORT, m_reader_port);
	DDV_MinMaxUInt(pDX, m_reader_port, 0, 65555);
	DDX_Text(pDX, IDC_SERNUM, m_sernum);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CUhfReaderDlg, CDialog)
	//{{AFX_MSG_MAP(CUhfReaderDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BTN_CONNECT, OnBtnConnect)
	ON_BN_CLICKED(IDC_BTN_CLOSEPORT, OnBtnCloseport)
	ON_BN_CLICKED(IDC_BTN_SETDEFAULT, OnBtnSetdefault)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BTN_READTAG, OnBtnReadtag)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST_CG, OnDblclkListCg)
	ON_BN_CLICKED(IDC_BTN_SAVE, OnBtnSave)
	ON_BN_CLICKED(IDC_READ_CONFIG, OnReadConfig)
	ON_BN_CLICKED(IDC_RADIO_ALLWAYS, OnRadioAllways)
	ON_BN_CLICKED(IDC_RADIO_TRIGGER_READ, OnRadioTriggerRead)
	ON_EN_CHANGE(IDC_EDIT_READCARD_DELAYTIME, OnChangeEditReadcardDelaytime)
	ON_EN_CHANGE(IDC_EDIT_WG_OUT_BYTE, OnChangeEditWgOutByte)
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_SETTING_ADDRESS, OnSettingAddress)
	ON_BN_CLICKED(IDC_GET_ADDRESS, OnGetAddress)
	ON_BN_CLICKED(IDC_READ_TAG2, OnReadTag2)
	ON_BN_CLICKED(IDC_READ_TAG16, OnReadTag16)
	ON_BN_CLICKED(IDC_RADIO_FCC, OnRadioFcc)
	ON_BN_CLICKED(IDC_RADIO_ETSI, OnRadioEtsi)
	ON_BN_CLICKED(IDC_RADIO_WG26, OnRadioWg26)
	ON_BN_CLICKED(IDC_RADIO_WG34, OnRadioWg34)
	ON_BN_CLICKED(IDC_READ_TAG_USB, OnReadTagUsb)
	ON_BN_CLICKED(IDC_RADIO_USB, OnRadioUsb)
	ON_BN_CLICKED(IDC_RADIO_COM, OnRadioCom)
	ON_BN_CLICKED(IDC_RADIO_TCP, OnRadioTcp)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUhfReaderDlg message handlers

/***********************************************************
** 函数名称: CString IntToASCII(unsigned char input)
** 功能描述: 将两位的无符号整数转换为字符串
** 输　  入:   unsigned char input : 16进制数
** 输    出:   input  的字符串形式  
 
** 例    如： 0xFF - > "FF" 
************************************************************/
CString IntToASCII1BYTED(unsigned char input)
{
	char temp[2];
	char exchange;
	CString output = "";		
	itoa(input,temp,16);		//结果高位放于temp[0],低位放于temp[1]
	if (temp[1] == 0)	        //因为如果input为0x0F 时，结果为 'F','0';	
	{						    //所以要交换一下temp[1]与temp[0]
		exchange = temp[1];
		temp[1]  = temp[0];
		temp[0]  = exchange;
	}	
//	if (temp[0] == 0)  output += "0";
// else	           output += temp[0]; 
	if (temp[1] == 0)  output += "0";
	   else            output += temp[1];
//output += temp[1];
	   return output;
}


/***********************************************************
** 函数名称: void StrToHex(CString str,__int16 len,unsigned char *databuff)
** 功能描述: 将一串字符串转换为一串两位的16进制数
** 输　  入: CString   str              : 输入的字符串
			 __int16   len              : 字符串的长度
			
** 输    出: unsigned char  *databuff   : 输出的16进制数串
 
** 例    如： "FF" - > 0xFF ; "1236" - > 12 36
** 备    注：len <= 24
************************************************************/
void StrToHex(CString str,__int16 len,unsigned char *databuff)
{
    __int16 intdata[12];							//len必须小于等于12	

	for (__int16 i = 0; i < len; i++)
	{
		CString StrChar = str.Mid(2 * i,2);			//取出其中的两个字符
		sscanf(StrChar,"%x",&intdata[i]);			//转换为16进制数
		databuff[i] = (unsigned char)intdata[i];
	}
}

BOOL CUhfReaderDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	CString	strCom="";
	CArray<SSerInfo,SSerInfo&> asi;
	EnumSerialPorts(asi,FALSE);
	int i = 0, k	=	asi.GetSize();
	for(i=0; i < k; i++)
	{
		int iComIndex =	0;
		int iComIndey =	0;
		strCom	=	asi[i].strFriendlyName;
		iComIndex = strCom.Find("COM");
		iComIndey = iComIndex;
		if ( iComIndex >= 0 )
		{
			iComIndex += 3;
			BOOL bFlag = FALSE;
			char *pp = (char*)(strCom.GetBuffer(MAX_PATH) + iComIndex);
			while ( *pp >= '0' && *pp <= '9' )
			{
				iComIndex++;
				pp++;
				
			}
			strCom.ReleaseBuffer();
			strCom = strCom.Mid(iComIndey, iComIndex-iComIndey);
		}
		else
		{
			break;
		}
		m_cbCom.AddString(strCom);
	}
	if (k <= 0)
	{
	//	MessageBox("No Comport");
	//	ExitProcess(0);
	}
	else m_cbCom.SetCurSel(0);
	m_cbBaud.AddString("9600");
	m_cbBaud.AddString("19200");
	m_cbBaud.AddString("38400");
	m_cbBaud.AddString("57600");
	m_cbBaud.AddString("115200");
	m_cbBaud.SetCurSel(0);

	m_comboBaud.AddString("9600");
	m_comboBaud.AddString("19200");
	m_comboBaud.AddString("38400");
	m_comboBaud.AddString("57600");
	m_comboBaud.AddString("115200");
	m_comboBaud.SetCurSel(4);

	//m_start_rf.SetCurSel(26);
	//m_end_rf.SetCurSel(36);

	CString str;
	//float m=0;
	int m=0;
	m_power.ResetContent();
	for(i=0; i<64; i++)
	{	
		str.Format("%d",m);
		m_power.AddString(str);
		m=m+1;
	}
	m_power.SetCurSel(5);

	m_out_len.ResetContent();
	m=1;
/*	for(i=0; i<12; i++)
	{	
		str.Format("%d",m);
		m_out_len.AddString(str);
		m=m+1;
	}
	m_out_len.SetCurSel(3);
	*/

	CString Result="";  
	CString ReadIpStr="192.168.1.250"; 
    WSADATA wsaData;   
    char Name[255];   
    hostent* hostinfo;   
    WORD wVersionRequested=MAKEWORD(2,2);   
    if (WSAStartup(wVersionRequested,&wsaData)==0)
	{   
		if (gethostname(Name,sizeof(Name))==0)
		{   
			hostinfo=gethostbyname(Name);   
            if(hostinfo!=NULL)   
				Result=inet_ntoa(*(struct in_addr *)*hostinfo->h_addr_list);   
        }   
        WSACleanup();         
    }
	m_host_ip.SetWindowText(Result);
	m_reader_ip.SetWindowText(ReadIpStr);//Read IP

	GetDlgItem(IDC_BTN_CONNECT)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_CLOSEPORT)->EnableWindow(FALSE);
	GetDlgItem(IDC_READ_CONFIG)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_SAVE)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_SETDEFAULT)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_READTAG)->EnableWindow(FALSE);
	m_IsOpen = FALSE;


	DWORD dwStyle = m_List6cID.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE);
	dwStyle |= LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES;
	m_List6cID.SendMessage(LVM_SETEXTENDEDLISTVIEWSTYLE, 0, (LPARAM)dwStyle);
	
	CString strTmp;
	char szTmp[256] = {0};
	char strPath[256] = {0};
	GetCurrentDirectory(256, szTmp);
	sprintf(strPath, "%s%s", szTmp, "\\config.ini");

	char szBuff[256] = {0};
	unsigned long ret = GetPrivateProfileString("Lan", "CONN_READER", "Reader Connection", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_CONN, szBuff);
	GetPrivateProfileString("Lan", "CONN_COMPORT", "Com Port:", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_CONNPORT, szBuff);
	GetPrivateProfileString("Lan", "CONN_BAUD", "Baudrate:", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_CONNBAUD, szBuff);
	GetPrivateProfileString("Lan", "BUTTON_CONNECT", "Connect", szBuff, 200, strPath);
	SetDlgItemText(IDC_BTN_CONNECT, szBuff);
	GetPrivateProfileString("Lan", "BUTTON_DISCONNECT", "Disconnect", szBuff, 200, strPath);
	SetDlgItemText(IDC_BTN_CLOSEPORT, szBuff);
	GetPrivateProfileString("Lan", "READER_INDICATE", "Reader Indicator", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_READER_INDECATE, szBuff);
	GetPrivateProfileString("Lan", "READER_BUZZER", "Buzzer", szBuff, 200, strPath);
	SetDlgItemText(IDC_CHECK_BUZZER, szBuff);
	GetPrivateProfileString("Lan", "BAUD_SET", "Address Setting", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_BAUD, szBuff);
	GetPrivateProfileString("Lan", "BAUD_BAUD", "Baudrate:", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_BAUD_BAUD, szBuff);
	GetPrivateProfileString("Lan", "MODE_WORKMODE", "Work Mode", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_WORKMODE, szBuff);
	GetPrivateProfileString("Lan", "MODE_ALLWAYS", "Read Always", szBuff, 200, strPath);
	SetDlgItemText(IDC_RADIO_ALLWAYS, szBuff);
	GetPrivateProfileString("Lan", "MODE_TRIGGER", "Read by Trigger", szBuff, 200, strPath);
	SetDlgItemText(IDC_RADIO_TRIGGER_READ, szBuff);
	GetPrivateProfileString("Lan", "MODE_READTIME", "Read Time\r\n(1-255):", szBuff, 200, strPath);
	strTmp = szBuff;
	strTmp.Replace("\\r\\n", "\r\n");
	SetDlgItemText(IDC_STATIC_READTIME, strTmp);
	GetPrivateProfileString("Lan", "MODE_S", "s", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_TIMES, szBuff);


	GetPrivateProfileString("Lan", "WEIGAND_26", "26", szBuff, 200, strPath);
	SetDlgItemText(IDC_RADIO_WG26, szBuff);
	GetPrivateProfileString("Lan", "WEIGAND_34", "34", szBuff, 200, strPath);
	SetDlgItemText(IDC_RADIO_WG34, szBuff);
	GetPrivateProfileString("Lan", "RF_RF", "RF Settings", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_RFSETTING, szBuff);
	GetPrivateProfileString("Lan", "RF_POWER", "Power", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_RFPOWER, szBuff);
	GetPrivateProfileString("Lan", "RF_FREQ", "Freq", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_RFFREQ, szBuff);
	GetPrivateProfileString("Lan", "RF_TO", "to", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_RFTO, szBuff);
	GetPrivateProfileString("Lan", "RF_HZ", "kHz", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_RFHZ, szBuff);
	GetPrivateProfileString("Lan", "BUTTON_READ_CONF", "Read Configuration", szBuff, 200, strPath);
	SetDlgItemText(IDC_READ_CONFIG, szBuff);
	GetPrivateProfileString("Lan", "BUTTON_FACTORY_DEFAULT", "Factory Default", szBuff, 200, strPath);
	SetDlgItemText(IDC_BTN_SETDEFAULT, szBuff);
	
	GetPrivateProfileString("Lan", "BUTTON_SAVE_CHANGES", "Save Changes", szBuff, 200, strPath);
	SetDlgItemText(IDC_BTN_SAVE, szBuff);
	
	GetPrivateProfileString("Lan", "BUTTON_READ_TAG", "Read Tag", szBuff, 200, strPath);
	SetDlgItemText(IDC_BTN_READTAG, szBuff);

	GetPrivateProfileString("Lan", "WIEGAND_OUTPUT_SETTINGS", "Wiegand Output Settings", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_WIEGAND_OUTPUT_SETTINGS , szBuff);

	GetPrivateProfileString("Lan", "WIEGAND_FORMAT", "Wiegand Format", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_WIEGAND_FORMAT , szBuff);

	GetPrivateProfileString("Lan", "TAG_READING_INTERVAL", "Tag Reading Interval", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_TAG_READING_INTERVAL , szBuff);
	

	GetPrivateProfileString("Lan", "TIME", "Time", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_TIME1 , szBuff);

	GetPrivateProfileString("Lan", "TIME", "Time", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_TIME2 , szBuff);


	GetPrivateProfileString("Lan", "START_BYTES", "Start Bytes", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_START_BYTES , szBuff);
	
	GetPrivateProfileString("Lan", "FORWARD_OUTPUT", "Forward Output", szBuff, 200, strPath);
	SetDlgItemText(IDC_RADIO_FORWARD , szBuff);

	GetPrivateProfileString("Lan", "INVERTED_OUTPUT", "Inverted Output", szBuff, 200, strPath);
	SetDlgItemText(IDC_RADIO_INVERTED , szBuff);
	
	GetPrivateProfileString("Lan", "LENGTH ", "Length", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_LENGTH , szBuff);


	GetPrivateProfileString("Lan", "OUTPUT_TIME ", "Output Time(1-20)", szBuff, 200, strPath);
	SetDlgItemText(IDC_STATIC_OUTPUT_TIME , szBuff);

	GetPrivateProfileString("Lan", "MESSAGE_SAVED", "Saved!", szBuff, 200, strPath);
	//SetDlgItemText(STRING_CONNECT_FAIL, szBuff);
	STRING_SAVED=szBuff;	

	GetPrivateProfileString("Lan", "MESSAGE_SUCCESS", "Success!", szBuff, 200, strPath);
	//SetDlgItemText(STRING_CONNECT_FAIL, szBuff);
	STRING_SUCCESS=szBuff;

	GetPrivateProfileString("Lan", "MESSAGE_CONNECT_FAIL", "Connection Fail!", szBuff, 200, strPath);
	//SetDlgItemText(STRING_CONNECT_FAIL, szBuff);
	STRING_CONNECT_FAIL=szBuff;

	GetPrivateProfileString("Lan", "MESSAGE_DISCONNECTED", "Disconnected!", szBuff, 200, strPath);
	//SetDlgItemText(STRING_CONNECT_FAIL, szBuff);
	STRING_DISCONNECTED=szBuff;
	
	GetPrivateProfileString("Lan", "MESSAGE_CONNECT_SUCCESFUL", "Connection Successful!", szBuff, 200, strPath);
//	SetDlgItemText(STRING_CONNECT_SUCCESFUL , szBuff);
	STRING_CONNECT_SUCCESFUL=szBuff;

	GetPrivateProfileString("Lan", "MESSAGE_GET_OUTPOWER_FAIL", "Get OutPower Fail!", szBuff, 200, strPath);
	//SetDlgItemText(STRING_GET_OUTPOWER_FAIL , szBuff);
	STRING_GET_OUTPOWER_FAIL=szBuff;
	
	GetPrivateProfileString("Lan", "MESSAGE_GET_WIEGAND_OUTPUT_SETTINGS_FAIL", "Get Wiegand Output Settings!", szBuff, 200, strPath);
	//SetDlgItemText(STRING_GET_WIEGAND_OUTPUT_SETTINGS_FAIL , szBuff);
	STRING_GET_WIEGAND_OUTPUT_SETTINGS_FAIL=szBuff;

		
	GetPrivateProfileString("Lan", "MESSAGE_SET_WIEGAND_OUTPUT_SETTINGS_FAIL", "Set Wiegand Output Settings!", szBuff, 200, strPath);
	//SetDlgItemText(STRING_GET_WIEGAND_OUTPUT_SETTINGS_FAIL , szBuff);
	STRING_SET_WIEGAND_OUTPUT_SETTINGS_FAIL=szBuff;


	GetPrivateProfileString("Lan", "MESSAGE_GET_FREQUENCY_REGION_FAIL", "Get Frequency Region Fail!", szBuff, 200, strPath);
//	SetDlgItemText(STRING_GET_FREQUENCY_REGION_FAIL , szBuff);
	STRING_GET_FREQUENCY_REGION_FAIL=szBuff;	
	GetPrivateProfileString("Lan", "MESSAGE_GET_ADDRESS_FAIL", "Get Address Fail!", szBuff, 200, strPath);
//	SetDlgItemText( STRING_GET_ADDRESS_FAIL, szBuff);
	STRING_GET_ADDRESS_FAIL=szBuff;	
	GetPrivateProfileString("Lan", "MESSAGE_GET_OUTPOWER_FAIL", "Get OutPowerFail!", szBuff, 200, strPath);
//	SetDlgItemText(STRING_GET_OUTPOWER_FAIL , szBuff);
	STRING_GET_OUTPOWER_FAIL=szBuff;	
	GetPrivateProfileString("Lan", "MESSAGE_READ_CONFIGURATION_OK", "Read Configuration OK!", szBuff, 200, strPath);
//	SetDlgItemText( STRING_READ_CONFIGURATION_OK, szBuff);
	STRING_READ_CONFIGURATION_OK=szBuff;

	GetPrivateProfileString("Lan", "MESSAGE_SET_FREQUENCY_REGION_FAIL", "Set Frequency Region Fail!", szBuff, 200, strPath);
//	SetDlgItemText( STRING_SET_FREQUENCY_REGION_FAIL, szBuff);
	STRING_SET_FREQUENCY_REGION_FAIL=szBuff;
	GetPrivateProfileString("Lan", "MESSAGE_SET_ADDRESS_FAIL", "Set Address Fail!", szBuff, 200, strPath);
	//SetDlgItemText(STRING_SET_ADDRESS_FAIL , szBuff);
	STRING_SET_ADDRESS_FAIL=szBuff;

	GetPrivateProfileString("Lan", "MESSAGE_GET_WIEGAND_OUTPUT_SETTINGS_FAIL", "Get Wiegand Output Settings Fail!", szBuff, 200, strPath);
	//SetDlgItemText( STRING_WIEGAND_OUTPUT_SETTINGS_FAIL, szBuff);
	STRING_GET_WIEGAND_OUTPUT_SETTINGS_FAIL=szBuff;

	GetPrivateProfileString("Lan", "MESSAGE_SET_WIEGAND_OUTPUT_SETTINGS_FAIL", "Set Wiegand Output Settings Fail!", szBuff, 200, strPath);
	//SetDlgItemText( STRING_WIEGAND_OUTPUT_SETTINGS_FAIL, szBuff);
	STRING_SET_WIEGAND_OUTPUT_SETTINGS_FAIL=szBuff;

	GetPrivateProfileString("Lan", "MESSAGE_FREQ_ERROR", "Freq Error!", szBuff, 200, strPath);
	//SetDlgItemText(STRING_FREQ_ERROR , szBuff);
	STRING_FREQ_ERROR=szBuff;
	GetPrivateProfileString("Lan", "MESSAGE_LENGHT_BYTES_PARAMETER_ERROR", "Lenght Bytes Parameter Error!", szBuff, 200, strPath);
	//SetDlgItemText(STRING_LENGHT_BYTES_PARAMETER_ERROR , szBuff);
	STRING_LENGHT_BYTES_PARAMETER_ERROR=szBuff;	
	GetPrivateProfileString("Lan", "MESSAGE_START_BYTES_PARAMETER_ERROR", "Start Bytes Parameter Error!", szBuff, 200, strPath);
	//SetDlgItemText(STRING_START_BYTES_PARAMETER_ERROR, szBuff);
	STRING_START_BYTES_PARAMETER_ERROR=szBuff;
	GetPrivateProfileString("Lan", "MESSAGE_READ_TIME_PARAMETER_ERROR", "Read Time Parameter Error!", szBuff, 200, strPath);
	//SetDlgItemText(STRING_READ_TIME_PARAMETER_ERROR , szBuff);
	STRING_READ_TIME_PARAMETER_ERROR=szBuff;
	GetPrivateProfileString("Lan", "MESSAGE_OUTPUT_TIME_PARAMETER_ERROR", "Output Time(1-20)", szBuff, 200, strPath);
	//SetDlgItemText( STRING_OUTPUT_TIME_PARAMETER_ERROR, szBuff);
	STRING_OUTPUT_TIME_PARAMETER_ERROR=szBuff;
	GetPrivateProfileString("Lan", "MESSAGE_DELETE", "Delete Record?", szBuff, 200, strPath);
	//SetDlgItemText( STRING_DELETE, szBuff);
	STRING_DELETE=szBuff;

	GetPrivateProfileString("Lan", "MESSAGE_WARNNING", "Warnning", szBuff, 200, strPath);
	//SetDlgItemText(STRING_WARNNING , szBuff);
	STRING_WARNNING=szBuff;

	GetPrivateProfileString("Lan", "MESSAGE_PARAMETER_ERROR", "Parameter Error!", szBuff, 200, strPath);
	//SetDlgItemText(STRING_PARAMETER_ERROR , szBuff);
	STRING_PARAMETER_ERROR=szBuff;


	GetPrivateProfileString("Lan", "LIST_NO", "No.", szBuff, 200, strPath);
	m_List6cID.InsertColumn(0, szBuff, LVCFMT_LEFT, 90);

	GetPrivateProfileString("Lan", "LIST_ID", "Card Number", szBuff, 200, strPath);
	m_List6cID.InsertColumn(1, szBuff, LVCFMT_LEFT, 250);

	GetPrivateProfileString("Lan", "LIST_SUCCESS_TIMES", "Success Times", szBuff, 200, strPath);
	m_List6cID.InsertColumn(2, szBuff, LVCFMT_LEFT, 150);

	GetPrivateProfileString("Lan", "LIST_EPCLEN", "EPC Length", szBuff, 200, strPath);
	m_List6cID.InsertColumn(3, szBuff, LVCFMT_LEFT, 150);
	

	defaultFre = 0;

	defaultParam.BaudRate = 0x8;			//(1)串口的通信速率，取值：00H~08H，代表速率同"设定波特率"命令。
	defaultParam.Power = 63;	//0x20;				//(2)发射功率值，取值：20~30dBm。(0-63)
	defaultParam.Min_Frequence = 1;	//0x7;		//(3)发射微波信号频率的起始点，取值： 1~63。
	defaultParam.Max_Frequence = 63;	//0x37;		//(4)发射微波信号频率的终止点，取值： 1~63。
	defaultParam.Reserve5 = 0xcc;			//(5)保留,后来改为调制深度
	defaultParam.WorkMode = 0x1;			//(6)读写器工作方式：0-主动方式，1-命令方式
	defaultParam.ReaderAddress = 0xa;		//(7)RS485地址:0--255
	defaultParam.NumofCard = 0xa;			//(8)最多读卡数目。
	defaultParam.TagType = 0x4;			//(9)标签种类：01H－ISO18000-6B，02H－EPCC1，04H－EPCC1G2，08H－EM4442。
	defaultParam.ReadDuration = 0x0;		//(10)读卡持续时间：射频发射持续时间，只针对EM标签有效；0－10ms，1－20ms，2－30ms，3－40ms。
	defaultParam.ReadTimes = 0x1;			//(11)读卡次数M：收到上位机读卡命令，读写器执行M次此命令。
	defaultParam.EnableBuzzer = 0x0;		//(12)1:使能蜂鸣器0:不使能蜂鸣器
	defaultParam.IP1 = 0xc0;			    //(13)读写器IP地址
	defaultParam.IP2 = 0xa8;			    //(14)
	defaultParam.IP3 = 0x01;			    //(15)
	defaultParam.IP4 = 0x64;			    //(16)
	defaultParam.Port1 = 0x7;				//(17)读写器端口高位
	defaultParam.Port2 = 0xb1;				//(18)
	defaultParam.Mask1 = 0xff;				//(19)读写器掩码1
	defaultParam.Mask2 = 0xff;				//(20)读写器掩码2
	defaultParam.Mask3 = 0xff;				//(21)读写器掩码3
	defaultParam.Mask4 = 0x0;				//(22)读写器掩码4
	defaultParam.Gateway1 = 0xc0;			//(23)读写器地址网关
	defaultParam.Gateway2 = 0xa8;			//(24)
	defaultParam.Gateway3 = 0x1;			//(25)
	defaultParam.Gateway4 = 0x1;			//(26)
	defaultParam.MAC1 = 0x00;			    //(27)读写器MAC地址
	defaultParam.MAC2 = 0x12;			    //(28)
	defaultParam.MAC3 = 0x34;			    //(29)
	defaultParam.MAC4 = 0x56;			    //(30)
	defaultParam.MAC5 = 0x78;			    //(31)
	defaultParam.MAC6 = 0x90;			    //(32)

	AfxBeginThread(EpgGetTagThread, this);
	//((CButton*)GetDlgItem(IDC_RADIO_COM))->SetCheck(true);
	//((CButton*)GetDlgItem(IDC_RADIO_TCP))->SetCheck(true);
	((CButton*)GetDlgItem(IDC_RADIO_USB))->SetCheck(true);

	GetDlgItem(IDC_RADIO_COM)->EnableWindow(FALSE);	
	GetDlgItem(IDC_RADIO_TCP)->EnableWindow(FALSE);	

	GetDlgItem(IDC_COMBO_OUT_LEN)->EnableWindow(FALSE);	
	GetDlgItem(IDC_RADIO_WG34)->EnableWindow(true);	
	GetDlgItem(IDC_RADIO_WG26)->EnableWindow(true);	
	
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}


void CUhfReaderDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);


    //计算TitleBar的坐标区域
    CRect titleRect;
    GetWindowRect(&titleRect);
    DWORD DialogBaseUnits = GetDialogBaseUnits();
    WORD DialogBaseUnits_X = LOWORD(DialogBaseUnits)/4;
    WORD DialogBaseUnits_Y = HIWORD(DialogBaseUnits)/8;
    titleRect.top += GetSystemMetrics(SM_CYBORDER) * DialogBaseUnits_Y;
    titleRect.left += GetSystemMetrics(SM_CXBORDER) * DialogBaseUnits_X;
    titleRect.right -= GetSystemMetrics(SM_CXBORDER) * DialogBaseUnits_X;
    titleRect.bottom = titleRect.top + GetSystemMetrics(SM_CYCAPTION);
 
    //创建DC设备
    CDC pDC;
    pDC.CreateDC("DISPLAY", NULL, NULL,NULL);
    int saveDC = pDC.SaveDC(); //保存设备
 
    //使用自定义颜色填充
    CBrush brush(RGB(255,0,0));
    pDC.FillRect(&titleRect,&brush);
 
    //正中位置显示字符串
    pDC.SetBkMode(TRANSPARENT);
    pDC.SetTextColor(RGB(0,128,128));
    pDC.DrawText("ABCD",titleRect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
 
    pDC.RestoreDC(saveDC); //恢复设备
    pDC.DeleteDC(); //删除设备


	// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

	// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CUhfReaderDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CUhfReaderDlg::OnBtnConnect() 
{
	// TODO: Add your control notification handler code here
	char strCom[10] = {0};
	int baud = 9600;
	int comport=0;
	unsigned char svalue;
	unsigned char workmode;
	unsigned char Version[50]={0};
	unsigned char SerNum[50]={0};
	unsigned char time;
	int i;
	int st;
	CString strSer;
	unsigned char Region;				
	int StartFreq,EndFreq,FreqSpace;
	unsigned char FreqQuantity;
	CString str;
	UpdateData(true);
	switch (m_comboBaud.GetCurSel())
	{
	case 0:
		baud = 9600;
		break;
	case 1:
		baud = 19200;
		break;
	case 2:
		baud = 38400;
		break;
	case 3:
		baud = 57600;
		break;
	case 4:
		baud = 115200;
		break;
	default:
		baud = 9600;
		break;
	}
	GetDlgItemText(IDC_CB_COMPORT, strCom, 10);
	comport=atoi(&strCom[3])-1;
	if(((CButton*)GetDlgItem(IDC_RADIO_TCP))->GetCheck())
	{
       /////////////////////////////TCP Connect//////////////////
		char ReaderIP[32]	=	{0};
		char HostIP[32]	=	{0};
		UpdateData(true); 
		DWORD dwIPAddress;
		CString m_strReaderIPAddress,m_strHostIPAddress;
		m_host_ip.GetAddress(dwIPAddress);
		m_strHostIPAddress.Format("%d.%d.%d.%d",
		HIBYTE(HIWORD(dwIPAddress)),
		LOBYTE(HIWORD(dwIPAddress)),
		HIBYTE(LOWORD(dwIPAddress)),
		LOBYTE(LOWORD(dwIPAddress))
		);
		m_reader_ip.GetAddress(dwIPAddress);
		m_strReaderIPAddress.Format("%d.%d.%d.%d",
		HIBYTE(HIWORD(dwIPAddress)),
		LOBYTE(HIWORD(dwIPAddress)),
		HIBYTE(LOWORD(dwIPAddress)),
		LOBYTE(LOWORD(dwIPAddress))
		);
		wsprintf(HostIP, "%s",LPCTSTR(m_strHostIPAddress));
		wsprintf(ReaderIP, "%s",LPCTSTR(m_strReaderIPAddress));
		st=Net_Connect(HostIP,m_host_port,ReaderIP,m_reader_port);
		if(st)
		{
			m_IsOpen = FALSE;
			m_status_display=STRING_CONNECT_FAIL;
			MessageBox(STRING_CONNECT_FAIL);
			UpdateData(false);
			return ;
		}

	}
	else
	{
		if(((CButton*)GetDlgItem(IDC_RADIO_USB))->GetCheck())comport=100;
		if(OpenCom(comport,baud))
		{
			GetDlgItem(IDC_BTN_CONNECT)->EnableWindow(TRUE);
			GetDlgItem(IDC_BTN_CLOSEPORT)->EnableWindow(FALSE);
			GetDlgItem(IDC_READ_CONFIG)->EnableWindow(FALSE);
			GetDlgItem(IDC_BTN_SAVE)->EnableWindow(FALSE);
			GetDlgItem(IDC_BTN_SETDEFAULT)->EnableWindow(FALSE);
			GetDlgItem(IDC_BTN_READTAG)->EnableWindow(FALSE);
			m_IsOpen = FALSE;
			m_status_display=STRING_CONNECT_FAIL;
			MessageBox(STRING_CONNECT_FAIL);
			UpdateData(false);
			CloseCom();
			return ;
		}
	}
///////////////////////////////////////////////////////////////////////////
	unsigned char WgOutByteData[4]={0x01,0x01,0x04,0x00};
	int ret=0;
	unsigned char addr;
	ret=Handshake(GlAddresss,1,GlReaderType,GlComMode);
	if (ret)
	{
		GetDlgItem(IDC_BTN_CONNECT)->EnableWindow(TRUE);
		GetDlgItem(IDC_BTN_CLOSEPORT)->EnableWindow(FALSE);
		GetDlgItem(IDC_READ_CONFIG)->EnableWindow(FALSE);
		GetDlgItem(IDC_BTN_SAVE)->EnableWindow(FALSE);
		GetDlgItem(IDC_BTN_SETDEFAULT)->EnableWindow(FALSE);
		GetDlgItem(IDC_BTN_READTAG)->EnableWindow(FALSE);
		m_IsOpen = FALSE;
		m_status_display=STRING_CONNECT_FAIL;
		MessageBox(STRING_CONNECT_FAIL);
		UpdateData(false);
		CloseCom();
		return;
	}
	else
	{
		m_IsOpen = TRUE;
		GetDlgItem(IDC_BTN_CONNECT)->EnableWindow(FALSE);
		GetDlgItem(IDC_BTN_CLOSEPORT)->EnableWindow(TRUE);
		GetDlgItem(IDC_READ_CONFIG)->EnableWindow(TRUE);
		GetDlgItem(IDC_BTN_SAVE)->EnableWindow(TRUE);
		GetDlgItem(IDC_BTN_SETDEFAULT)->EnableWindow(TRUE);
		GetDlgItem(IDC_BTN_READTAG)->EnableWindow(TRUE);
		m_IsOpen = FALSE;
		m_status_display=STRING_CONNECT_SUCCESFUL;
		UpdateData(false);
	}
//EnableAllButton(TRUE);
//return;
//int __stdcall Handshake(unsigned char DevcieAddr,unsigned char CmdData,
//unsigned char &Status2);
//UhfSetWorkMode(GlAddresss,0);
	UhfGetBuzzer(GlAddresss,svalue);
	if (svalue ==0x00)
	{
		((CButton*)GetDlgItem(IDC_CHECK_BUZZER))->SetCheck(FALSE);
	}
	else
	{
		((CButton*)GetDlgItem(IDC_CHECK_BUZZER))->SetCheck(TRUE);
		
	}
	//工作模式
	UhfGetWorkMode(GlAddresss,workmode);
	if (workmode == 0x01)
	{
		((CButton*)GetDlgItem(IDC_RADIO_ALLWAYS))->SetCheck(FALSE);
		((CButton*)GetDlgItem(IDC_RADIO_TRIGGER_READ))->SetCheck(TRUE);
		GetDlgItem(IDC_EDIT_TRIGGER_TIME)->EnableWindow(TRUE);
	}
	else
	{
		((CButton*)GetDlgItem(IDC_RADIO_TRIGGER_READ))->SetCheck(FALSE);
		((CButton*)GetDlgItem(IDC_RADIO_ALLWAYS))->SetCheck(TRUE);
		GetDlgItem(IDC_EDIT_TRIGGER_TIME)->EnableWindow(FALSE);
	}
	ret=UhfGetTriggerTime(GlAddresss,m_trigger_time);//1
	ret = UhfGetWgIntervalTime(GlAddresss,time);//1
	m_wg_time=time;//2
	UpdateData(false);
	ret =UhfGetWgOutByte(GlAddresss,WgOutByteData);
	if(ret)
	{
		MessageBox(STRING_GET_WIEGAND_OUTPUT_SETTINGS_FAIL);
		return ;
	}
	if (WgOutByteData[3] ==0)
	{
		((CButton*)GetDlgItem(IDC_RADIO_FORWARD))->SetCheck(TRUE);
		((CButton*)GetDlgItem(IDC_RADIO_INVERTED))->SetCheck(FALSE);
	}
	else
	{
		((CButton*)GetDlgItem(IDC_RADIO_INVERTED))->SetCheck(TRUE);
		((CButton*)GetDlgItem(IDC_RADIO_FORWARD))->SetCheck(FALSE);
	}

	strSer.Format("%d",WgOutByteData[1]);
	SetDlgItemText(IDC_EDIT_WG_OUT_BYTE, strSer);

	int m=0;
	m_start_byte.ResetContent();
	m=0;
	for(i=0; i<12; i++)
	{	
		str.Format("%d",m);
		m_start_byte.AddString(str);
		m=m+1;
	}
	m_start_byte.SetCurSel(WgOutByteData[1]);	

	if(((CButton*)GetDlgItem(IDC_RADIO_USB))->GetCheck())
	{
		ret =UhfGetWeigand(GlAddresss,svalue);
		if (svalue == 0x26)
		{
			((CButton*)GetDlgItem(IDC_RADIO_WG26))->SetCheck(TRUE);
			((CButton*)GetDlgItem(IDC_RADIO_WG34))->SetCheck(FALSE);
		}
		else if (svalue == 0x34)
		{
			((CButton*)GetDlgItem(IDC_RADIO_WG34))->SetCheck(TRUE);
			((CButton*)GetDlgItem(IDC_RADIO_WG26))->SetCheck(FALSE);
		}
	}
	else
	{
		m_out_len.SetCurSel(WgOutByteData[2]-1);
		((CButton*)GetDlgItem(IDC_RADIO_WG26))->SetCheck(FALSE);
		((CButton*)GetDlgItem(IDC_RADIO_WG34))->SetCheck(FALSE);
	}
	unsigned char Status;
	unsigned char Password[4];
	unsigned char Value;
	st= UhfGetPassword(GlAddresss,Status,Password);
	if (Status)
	{
		((CButton*)GetDlgItem(IDC_RADIO_YES))->SetCheck(TRUE);
		((CButton*)GetDlgItem(IDC_RADIO_NO))->SetCheck(FALSE);
	}
	else
	{
		((CButton*)GetDlgItem(IDC_RADIO_YES))->SetCheck(FALSE);
		((CButton*)GetDlgItem(IDC_RADIO_NO))->SetCheck(TRUE);
	}
	strSer="";
	for( i = 0;i<4;i++)
	{
		strSer +=IntToASCII(Password[i]);
	}
	m_password=strSer;
	SetDlgItemText(IDC_EDIT_PASSWORD, strSer);
	st=UhfGetReadTagIntervalTime(GlAddresss,Value);//2
	strSer.Format("%d",Value);
	SetDlgItemText(IDC_EDIT_READCARD_DELAYTIME, strSer);
	ret=UhfGetOutPower(GlAddresss,svalue);
	if(ret)
	{
		MessageBox(STRING_SET_OUTPOWER_FAIL);
		return ;
	}

	if(GlReaderType==0x02)
	{
		m=0;
		m_power.ResetContent();
		for(i=0; i<64; i++)
		{	
			str.Format("%d",m);
			m_power.AddString(str);
			m=m+1;
		}
		m_power.SetCurSel(svalue);
	}
	if(GlReaderType==0x01)
	{
		m=18;
		m_power.ResetContent();
		for(i=0; i<9; i++)
		{	
			str.Format("%d",m);
			m_power.AddString(str);
			m=m+1;
		}
		m_power.SetCurSel((svalue-18));
		UpdateData(false);
	}
	if(GlReaderType==0x00)
	{
		m=0;
		m_power.ResetContent();
		for(i=0; i<34; i++)
		{	
			str.Format("%d",m);
			m_power.AddString(str);
			m=m+1;
		}
		m_power.SetCurSel((svalue));
		UpdateData(false);
	}
	Get_Version(GlAddresss,Version);
	m_version=Version;
	ret=Get_SerNum(GlAddresss,SerNum);
	if(ret==0)
	{
		strSer="SN:";
		for( i = 0;i<12;i++)
		{
			strSer +=IntToASCII((SerNum[i]));
		}
		m_sernum=strSer;
	}

	ret=UhfGetAddress(GlAddresss,Value);
	if(ret)
	{
		MessageBox(STRING_GET_ADDRESS_FAIL);
		return ;
	}
	m_address=Value;
	ret=UhfGetFrequencyRegion(GlAddresss,Region,StartFreq,EndFreq,
					 FreqSpace,FreqQuantity);
	if(GlReaderType==0x02)
	{

		BYTE imin	=	StartFreq-1;
		BYTE imax	=	EndFreq-1;
		m_bFre=0;//只支持美标
		//UpdateData(true);
		OnCbnSetFre(m_bFre, imin, imax);//因为通过国家来，每个国家的频率有些不一样的
		UpdateData(false);
	}
	else
	{
		//罗丹贝尔模块
		CString str;
		int m=0;
		int i;
		if(StartFreq>=902000)///////////////
		{
			((CButton*)GetDlgItem(IDC_RADIO_FCC))->SetCheck(true);
			((CButton*)GetDlgItem(IDC_RADIO_ETSI))->SetCheck(false);
			m_start_rf.ResetContent();
			/////////////////////////////美标///////////////////////
			m=902000;
			for(i=0; i<53; i++)
			{	
				str.Format("%d",m);
				m_start_rf.AddString(str);
				m=m+500;
			}
			
			m_end_rf.ResetContent();
			m=902000;
			for(i=0; i<53; i++)
			{	
				str.Format("%d",m);
				m_end_rf.AddString(str);
				m=m+500;
			}
			m_start_rf.SetCurSel(((StartFreq-902000)/500));
			m_end_rf.SetCurSel(((StartFreq-902000)/500)+FreqQuantity);
		}
		else
		{

	/////////////////////////欧标////////////////////////////////////
			((CButton*)GetDlgItem(IDC_RADIO_FCC))->SetCheck(false);
			((CButton*)GetDlgItem(IDC_RADIO_ETSI))->SetCheck(true);
			m_start_rf.ResetContent();
			m=865000;
			for(i=0; i<7; i++)
			{	
				str.Format("%d",m);
				m_start_rf.AddString(str);
				m=m+500;
			}
			//m_start_rf.SetCurSel(0);
			m=865000;
			m_end_rf.ResetContent();
			for(i=0; i<7; i++)
			{	
				str.Format("%d",m);
				m_end_rf.AddString(str);
				m=m+500;
			}
			m_start_rf.SetCurSel(((StartFreq-865000)/500));
			m_end_rf.SetCurSel(((StartFreq-865000)/500)+FreqQuantity);	
		
		}




		UpdateData(false);
	}

//UhfSetOutPower(GlAddresss,20);
//UhfGetOutPower(GlAddresss,svalue);
//int __stdcall UhfSetTriggerTime(unsigned char DevcieAddr,unsigned char TimeValue);


	return;

}

/*
命令码: 01H
命令参数:1个字节BPS，取值:00H~08H，分别代表:
04H	9600bps
05H	19200bps
06H	38400bps
07H	57600bps
08H	115200bps
命令包: 『40H  03H  01H  BPS  CheckSum』
*/


/*
命令码: 0BH
命令参数:1个字节BPS，取值:00H~FFH，分别代表:
0x00-0xFF(不可为0和FF，将返回错误)
命令包: 『40H  03H  0BH  BPS  CheckSum』
*/

/*
命令码: 0CH
命令参数:1个字节BPS，取值:00H~FFH，分别代表:
0x00-0xFF(不可为0和FF，将返回错误)
命令包: 『40H  03H  0CH  BPS  CheckSum』
*/

/*
命令码: 0DH
命令参数:1个字节BPS，取值:00H~98H，分别代表:
0x26
0x34
(后续根据客户需求添加，现只支持两种)
命令包: 『40H  03H  0DH  BPS  CheckSum』
*/


/*
命令码: 0xFF
命令参数:1个字节BPS，取值:0x00、0x01、0x10、0x11，分别代表:

低字节控制蜂鸣器，
高字节控制LED灯
预留控制四个BUZ和四个LED灯

命令包: 『40H  03H  FFH  BPS  CheckSum』
*/

/*
正确：命令包: 『F0H  02H 命令码 CheckSum』
错误：命令包: 『F4H  03H 命令码 错误码（可能为出错后读取FLASH存储值，即设置错误后，值为多少）CheckSum』
*/

void CUhfReaderDlg::OnBtnCloseport() 
{
	// TODO: Add your control notification handler code here
	
	unsigned char svalue;
	//Handshake(GlAddresss,0,svalue);
	Handshake(GlAddresss,0,GlReaderType,GlComMode);
	CloseCom();
	GetDlgItem(IDC_BTN_CONNECT)->EnableWindow(TRUE);
	GetDlgItem(IDC_BTN_CLOSEPORT)->EnableWindow(FALSE);
	GetDlgItem(IDC_READ_CONFIG)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_SAVE)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_SETDEFAULT)->EnableWindow(FALSE);
	GetDlgItem(IDC_BTN_READTAG)->EnableWindow(FALSE);
	m_IsOpen = FALSE;
	m_status_display=STRING_DISCONNECTED;
	UpdateData(false);

}

void CUhfReaderDlg::OnBtnSetdefault() 
{
	// TODO: Add your control notification handler code here
//	int ret = guhfapi.UhfReadFactoryParameter(0);
	unsigned char config[6];
	unsigned char time;
	unsigned char Region;				
	int StartFreq,EndFreq,FreqSpace;
	unsigned char FreqQuantity;

	int ret = 0;
	UpdateData(true);
	ret=UhfFactoryDefault(GlAddresss);
	ret=UhfSetAddress(GlAddresss,1);
	UhfSetWgIntervalTime(GlAddresss,2);
	UhfSetTriggerTime(GlAddresss,3);
	UhfSetWeigand(GlAddresss,0x26);
//	ret=UhfSetFrequencyRegion(GlAddresss,0x04,StartFreq,EndFreq,
				// FreqSpace,FreqQuantity);
	UhfSetWorkMode(GlAddresss,0x00);
	if(GlReaderType==0x00)
	{
	//	ret=UhfSetFrequencyRegion(GlAddresss,0x04,902000,928000,
					//	500,52)
				//500,52);
		ret=UhfGetFrequencyRegion(GlAddresss,Region,StartFreq,EndFreq,
						 FreqSpace,FreqQuantity);
		if(ret==0)
		{
			if(StartFreq>=902000)
			{
				ret=UhfSetFrequencyRegion(GlAddresss,0x04,902000,928000,
								500,52);//美标
			}
			else
			{
				ret=UhfSetFrequencyRegion(GlAddresss,0x04,865000,868000,
									500,6);//欧标
			}
		}
		ret=UhfSetOutPower(GlAddresss,33);		
	}
	if(GlReaderType==0x01)//低成本
	{
		//et=UhfSetFrequencyRegion(GlAddresss,0x04,902000,928000,
				//500,52);
		ret=UhfGetFrequencyRegion(GlAddresss,Region,StartFreq,EndFreq,
						 FreqSpace,FreqQuantity);
		if(ret==0)
		{
			if(StartFreq>=902000)
			{
				ret=UhfSetFrequencyRegion(GlAddresss,0x04,902000,928000,
								500,52);//美标
			}
			else
			{
				ret=UhfSetFrequencyRegion(GlAddresss,0x04,865000,868000,
									500,6);//欧标
				
			}
		}
	//	else
	//	{
		//	MessageBox("Get FrequencyRegion Fail!");
		//	return ;			
		//}
		ret=UhfSetOutPower(GlAddresss,26);		
	}

	if(GlReaderType==0x02)
	{

		ret=UhfSetFrequencyRegion(GlAddresss,5,1,63,0,0);
		ret=UhfSetOutPower(GlAddresss,63);		
	}

	if (ret)
	{
		MessageBox(STRING_CONFIGURE_FAIL);
		return ;
	}
	m_status_display=STRING_SUCCESS;
	UpdateData(false);
}

int RUhfReadTag(void *pParent, BYTE *data, int dwLen)
{
	//	CEpccgDlg *pThis = (CEpccgDlg*)pParent;
	CUhfReaderDlg *pThis = (CUhfReaderDlg *)pParent;
	//	pThis->EPCC1G2ReadTag(data, dwLen);
	pThis->RuhfReadTag(data, dwLen);
	return 0;
}

//#define AUTO_READ_EPC

#define MAX_LABELS 255
#define ID_MAX_SIZE_96BIT 65

BYTE EPCC1G2_IDBuffer[MAX_LABELS][ID_MAX_SIZE_96BIT]={0};
void CUhfReaderDlg::RuhfReadTag(void *data, DWORD dwLen)
{
	BYTE bData[256];
	int m_epcLen = 0;
	memcpy(bData, data, dwLen);
	m_epcLen=dwLen;
//	if (m_wg34)
//	{
//	sprintf(data, "%010u", htonl(*(unsigned long*)tmpbuff));
//	}
//	else
//	{
//	unsigned char epc[4];
//	memcpy(epc, &tmpbuff[npLen], 4);
//	epc[0] = 0;
//	sprintf(data, "%010u", htonl(*(unsigned long*)epc));
//	}
	
		char s[256] = {0};
		CString strTmp,str;
		int i,j;
		m_List6cID.DeleteAllItems();
		for(j=0;j<1;j++)
		{
			m_List6cID.InsertItem(j,IntToASCII1BYTED(j));//插入0 行
			
		}
		int epcaddr=0;
		strTmp="";
		str="";
		char temdata[256];
		sprintf(temdata,"%010u", htonl(*(unsigned long*)bData));
		for(i=0;i<m_epcLen;i++)
		{
			str+=temdata[i];
		}
		m_List6cID.SetItemText(0, 1, str);

	return ;
}
void CUhfReaderDlg::RuhfReadTag2(void *data, DWORD dwLen)
{
	BYTE bData[256];
	int m_epcLen = 0;
	memcpy(&bData[m_epcLen], data, dwLen);
	m_epcLen += dwLen;
	giTimes++;
	CString str_temp, str;
	char temp[64];
	int ID_len_temp, ID_len;
	while (m_epcLen > 2)
	{
		if (bData[0] == 0xF0)
		{
			if ( !(m_epcLen >= bData[1] + 2) )
				return ;
			BYTE bEPC[40];
			int iEPCLen = 0;
			if (bData[1] + 2 > m_epcLen)
			{
				return ;
			}
			if (bData[bData[1] + 1] != Uhf_CheckSum(bData, bData[1] + 1))
			{
				//校验错误
				m_epcLen = 0;
				continue;
			}
			if (bData[2] != 0xEE)	//命令错误
			{
				m_epcLen = 0;
				continue;
			}
			BYTE tmpbuff[256];
			int dataLen = bData[1] - 2;
			int epcDataLen = bData[3];
			memcpy(tmpbuff, &bData[4], dataLen);
//			CListCtrl *pListCG = (CListCtrl *)pThis->GetDlgItem(IDC_LIST_CG);
			CListCtrl *pListCG = (CListCtrl *)GetDlgItem(IDC_LIST_CG);
			int count = pListCG->GetItemCount();
			int k = count;
//			int k = 0;
			int kk = 0, npLen = 1, nCounter = epcDataLen;
			for (kk = 0; kk < epcDataLen; kk++)
			{
				char data[256] = {0};
				int nLen = tmpbuff[npLen - 1];
//				Byte2HexChar(&tmpbuff[npLen], nLen*2, data);
#if 0
				sprintf(data, "%010u", htonl(*(unsigned long*)&tmpbuff[npLen]));
#else
				if (m_wg34)
				{
					//sprintf(data, "%010u", htonl(*(unsigned long*)&tmpbuff[npLen]));
					sprintf(data, "%010u", htonl(*(unsigned long*)&tmpbuff[npLen+4]));//读取 5 6 7 8 字节
				}
				else
				{
					unsigned char epc[4];
				//	memcpy(epc, &tmpbuff[npLen], 4);
					memcpy(epc, &tmpbuff[npLen+4], 4);//读取 5 6 7 8 字节
					epc[0] = 0;
					sprintf(data, "%010u", htonl(*(unsigned long*)epc));
				}
#endif

				memcpy(bEPC, &tmpbuff[npLen], nLen*2);
				npLen += nLen*2 + 1;
				iEPCLen = nLen*2;
				str = data;
				ID_len = nLen * 2;
				//////////////////////////////////////////////////////////////////////////
				int i = kk;
				int j = 0;
#if 1
				for(j=0;j<k;j++)
				{
					m_List6cID.GetItemText(j, 4, temp, 3);
					
					ID_len_temp=((BYTE)strtol(temp, NULL, 16))*2;
					if (ID_len == ID_len_temp)
					{
						m_List6cID.GetItemText(j, 1, temp, 64);
						str_temp=temp;
						if(str == str_temp) break;
					}
				}
				if(j == k)
				{
					m_List6cID.InsertItem(k,itoa(k+1,temp,10));
					m_List6cID.SetItemText(k,1,str);
					m_List6cID.SetItemText(k,2,"1");
					str_temp.Format("%02X",EPCC1G2_IDBuffer[i][0]);
					str_temp.Format("%d", iEPCLen / 2);
					m_List6cID.SetItemText(k,4,str_temp);
					m_List6cID.EnsureVisible(k,TRUE);
					k++;
					
					m_tag6C.m_iIndex = m_listTag.size();
					memcpy(m_tag6C.m_bTagID, bEPC, iEPCLen);
					m_tag6C.m_iTagLen = iEPCLen;
					m_tag6C.m_strTagID = str;
					m_listTag.push_back(m_tag6C);
					/*
					m_cbRWTagID.AddString(str);
					m_cbKillTagID.AddString(str);
					m_cbProtectTagID.AddString(str);
					m_cbLockTagIDUser.AddString(str);
					m_cbAlarmTagID.AddString(str);
					m_cbReadProtectTagID.AddString(str);
					
					if (k == 1)
						SetDlgItemText(IDC_EDIT_UNLOCK_READ, str);
					
					m_cbRWTagID.SetCurSel(0);
					m_cbKillTagID.SetCurSel(0);
					m_cbProtectTagID.SetCurSel(0);
					m_cbLockTagIDUser.SetCurSel(0);
					m_cbAlarmTagID.SetCurSel(0);
					m_cbReadProtectTagID.SetCurSel(0);
					*/
				}
				else
				{
					str_temp=m_List6cID.GetItemText(j,2);
					m_List6cID.SetItemText(j, 2, itoa(atoi(str_temp)+1, temp, 10));
				}
#endif
			}
			m_epcLen = m_epcLen - bData[1] - 2;
			epcDataLen = bData[1] + 2;
			if (epcDataLen + m_epcLen > 512)
			{
				m_epcLen = 0;
				break;
			}
			else
				memcpy(bData, &bData[epcDataLen], m_epcLen);
		}
		else
		{
			int ii = 0;
			while (m_epcLen > 0)
			{
				if (bData[ii] != 0xF0)
				{
					ii++;
					m_epcLen--;
				}
				else
				{
					memcpy(bData, &bData[ii], m_epcLen);
					break;
				}
			}
//			m_epcLen = 0;
		}
	}
	return ;
}

void CUhfReaderDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	if (m_hEpccEvent)
	{
		m_IsExitReadEPC = TRUE;
		m_iAutoReadFlag = FALSE;
		SetEvent(m_hEpccEvent);
		CloseHandle(m_hEpccEvent);
		m_hEpccEvent = NULL;
	}
	CDialog::OnClose();
}

UINT CUhfReaderDlg::EpgGetTagThread(void *lpVoid)
{
	CUhfReaderDlg * pThis = (CUhfReaderDlg*)lpVoid;
	pThis->EpgGetTag();
	return 0;
}
int CUhfReaderDlg::EpgGetTag()
{
	return 0;
	int nCounter = 0;
	m_rdListRegion = 1;
	ResetEvent(m_hEpccEvent);
	while (!m_IsExitReadEPC)
	{
		giTimes = 0;
		WaitForSingleObject(m_hEpccEvent, INFINITE);
		while(m_iAutoReadFlag)
		{
#if 1
		//	UhfAutoReadLabelID(m_rdListRegion, 0, 0, NULL, IDBuffer, &nCounter, RUhfReadTag, this);
#else
			if (UhfSetAntenna(1))
			{
//				return ;
			}
#endif
//			Sleep(10);
		}
	}
	return 0;
}

void CUhfReaderDlg::OnCbnSetFre(int sel, int imin, int imax)
{
	int i = 0;
	int k = 0;
	int iCount = 0;
	long iValue = 0;
	CString strFreqTmp;
	tagReaderFreq tmpFreq;
	CComboBox *m_MinFrequency	=	(CComboBox*)GetDlgItem(IDC_COMBO_START_RF);
	CComboBox *m_MaxFrequency	=	(CComboBox*)GetDlgItem(DC_COMBO_END_RF);
	//频率计算公式
	//级数 = 50;
	//步进 = 500KHz;
	//起始频率 = 902750;
	//902750 + 级数*步进;
	m_MinFrequency->ResetContent();
	m_MaxFrequency->ResetContent();
	switch(sel)
	{
	case 0://{"0---FCC（美国）", 50, 500, 902750},								//(0)
	case 1://{"1---ETSI EN 300-220（欧洲300-220）", -1, -1, -1},				//(1)
	case 2://{"2---ETSI EN 302-208（欧洲302-208）", 4, 600, 865700},			//(2)
	case 3://"3---HK920-925香港", 10, 500, 920250},							//(3)
	case 4://{"4---TaiWan 922-928台湾", 12, 500, 922250},						//(4)
	case 5://{"5---Japan 952-954日本", 0, 0, 0},								//(5)
	case 6://{"6---Japan 952-955日本", 14,200, 952200},						//(6)
	case 7://{"7---ETSI EN 302-208欧洲", 4, 600, 865700},						//(7)
	case 8://{"8---Korea 917-921韩国", 6, 600, 917300},						//(8)
	case 9://{"9---Malaysia 919-923马来西亚", 8, 500, 919250},					//(9)
	case 10://{"10--China 920-925中国", 16, 250, 920625},						//(10)
	case 11://{"11--Japan 952-956日本", 4, 1200, 952400},						//(11)
	case 12://{"12--South Africa 915-919南美", 17, 200, 915600},				//(12)
	case 13://{"13--Brazil 902-907/915-928巴西", 35, 500, 902750},				//(13)
	case 14://{"14--Thailand 920-925泰国", -1, -1, -1},						//(14)
	case 15://{"15--Singapore 920-925新加坡", 10, 500, 920250},				//(15)
	case 16://{"16--Australia 920-926澳洲", 12, 500, 920250},					//(16)
	case 17://{"17--India 865-867印度", 4, 600, 865100},						//(17)
	case 18://{"18--Uruguay 916-928乌拉圭", 23, 500, 916250},					//(18)
	case 19://{"19--Vietnam 920-925越南", 10, 500, 920250},					//(19)
	case 20://{"20--Israel 915-917", 1, 0, 916250},							//(20)
	case 21://{"21--Philippines 918-920菲律宾", 4, 500, 918250},				//(21)
	case 22://{"22--Canada 902-928加拿大", 42, 500, 902750},					//(22)
	case 23://{"23--Indonesia 923-925印度尼西亚", 4, 500, 923250},				//(23)
	case 24://{"24--New Zealand 921.5-928新西兰", 11, 500, 922250},			//(24)
		tmpFreq.iGrade	=	stuctFreqCountry[sel].iGrade;
		tmpFreq.iSkip	=	stuctFreqCountry[sel].iSkip;
		tmpFreq.dwFreq	=	stuctFreqCountry[sel].dwFreq;
		k = 0;
		iCount	=	tmpFreq.iGrade;
		if ( 22 == sel )
		{
			int iArray[3] = {902750, 903250, 905750};
			//加拿大的特述
			for (i = 0; i < 3; i++)
			{
				strFreqTmp.Format("%02d--%d", i+1, iArray[i]);
				m_MinFrequency->AddString(strFreqTmp);
				m_MaxFrequency->AddString(strFreqTmp);
			}
			tmpFreq.dwFreq	=	iArray[i-1];
			iCount			=	tmpFreq.iGrade - 3;
			k = 3;
		}	
		for (i = k; i < iCount + k; i++)
		{
			iValue	=	tmpFreq.dwFreq + i * tmpFreq.iSkip;
			strFreqTmp.Format("%02d--%d", i+1, iValue);
			m_MinFrequency->AddString(strFreqTmp);
			m_MaxFrequency->AddString(strFreqTmp);
		}
		iCount	=	tmpFreq.iGrade;
		if ( i > 0 )
		{
			if ( imin == -1 && imax == -1 )
			{
				m_MinFrequency->SetCurSel(0); 
				m_MaxFrequency->SetCurSel(iCount - 1); 
			}
			else
			{
				m_MinFrequency->SetCurSel(imin); 
				m_MaxFrequency->SetCurSel(imax); 
			}
		}
		break;
	default:
		break;
	}
}
void CUhfReaderDlg::OnCbnSetFreold(int sel, int imin, int imax)
{
	int i = 0;
	int k = 0;
	int iCount = 0;
	long iValue = 0;
	CString strFreqTmp;
	tagReaderFreq tmpFreq;
	CComboBox *m_MinFrequency	=	(CComboBox*)GetDlgItem(IDC_CB_MINFREQ);
	CComboBox *m_MaxFrequency	=	(CComboBox*)GetDlgItem(IDC_CB_MAXFREQ);
	//频率计算公式
	//级数 = 50;
	//步进 = 500KHz;
	//起始频率 = 902750;
	//902750 + 级数*步进;
	m_MinFrequency->ResetContent();
	m_MaxFrequency->ResetContent();
	switch(sel)
	{
	case 0://{"0---FCC（美国）", 50, 500, 902750},								//(0)
	case 1://{"1---ETSI EN 300-220（欧洲300-220）", -1, -1, -1},				//(1)
	case 2://{"2---ETSI EN 302-208（欧洲302-208）", 4, 600, 865700},			//(2)
	case 3://"3---HK920-925香港", 10, 500, 920250},							//(3)
	case 4://{"4---TaiWan 922-928台湾", 12, 500, 922250},						//(4)
	case 5://{"5---Japan 952-954日本", 0, 0, 0},								//(5)
	case 6://{"6---Japan 952-955日本", 14,200, 952200},						//(6)
	case 7://{"7---ETSI EN 302-208欧洲", 4, 600, 865700},						//(7)
	case 8://{"8---Korea 917-921韩国", 6, 600, 917300},						//(8)
	case 9://{"9---Malaysia 919-923马来西亚", 8, 500, 919250},					//(9)
	case 10://{"10--China 920-925中国", 16, 250, 920625},						//(10)
	case 11://{"11--Japan 952-956日本", 4, 1200, 952400},						//(11)
	case 12://{"12--South Africa 915-919南美", 17, 200, 915600},				//(12)
	case 13://{"13--Brazil 902-907/915-928巴西", 35, 500, 902750},				//(13)
	case 14://{"14--Thailand 920-925泰国", -1, -1, -1},						//(14)
	case 15://{"15--Singapore 920-925新加坡", 10, 500, 920250},				//(15)
	case 16://{"16--Australia 920-926澳洲", 12, 500, 920250},					//(16)
	case 17://{"17--India 865-867印度", 4, 600, 865100},						//(17)
	case 18://{"18--Uruguay 916-928乌拉圭", 23, 500, 916250},					//(18)
	case 19://{"19--Vietnam 920-925越南", 10, 500, 920250},					//(19)
	case 20://{"20--Israel 915-917", 1, 0, 916250},							//(20)
	case 21://{"21--Philippines 918-920菲律宾", 4, 500, 918250},				//(21)
	case 22://{"22--Canada 902-928加拿大", 42, 500, 902750},					//(22)
	case 23://{"23--Indonesia 923-925印度尼西亚", 4, 500, 923250},				//(23)
	case 24://{"24--New Zealand 921.5-928新西兰", 11, 500, 922250},		    	//(24)
		tmpFreq.iGrade	=	stuctFreqCountry[sel].iGrade;
		tmpFreq.iSkip	=	stuctFreqCountry[sel].iSkip;
		tmpFreq.dwFreq	=	stuctFreqCountry[sel].dwFreq;
		k = 0;
		iCount	=	tmpFreq.iGrade;
		if ( 22 == sel )
		{
			int iArray[3] = {902750, 903250, 905750};
			//加拿大的特述
			for (i = 0; i < 3; i++)
			{
				strFreqTmp.Format("%02d--%d", i+1, iArray[i]);
				m_MinFrequency->AddString(strFreqTmp);
				m_MaxFrequency->AddString(strFreqTmp);
			}
			tmpFreq.dwFreq	=	iArray[i-1];
			iCount			=	tmpFreq.iGrade - 3;
			k = 3;
		}
		for (i = k; i < iCount + k; i++)
		{
			iValue	=	tmpFreq.dwFreq + i * tmpFreq.iSkip;
			strFreqTmp.Format("%02d--%d", i+1, iValue);
			m_MinFrequency->AddString(strFreqTmp);
			m_MaxFrequency->AddString(strFreqTmp);
		}
		iCount	=	tmpFreq.iGrade;
		if ( i > 0 )
		{
			if ( imin == -1 && imax == -1 )
			{
				m_MinFrequency->SetCurSel(0); 
				m_MaxFrequency->SetCurSel(iCount - 1); 
			}
			else
			{
				m_MinFrequency->SetCurSel(imin); 
				m_MaxFrequency->SetCurSel(imax); 
			}
		}
		break;
	default:
		break;
	}
}
void CUhfReaderDlg::OnBtnReadtag() 
{
	if ((m_start_byte.GetCurSel()+m_out_len.GetCurSel()+1)>12)	
	{
		MessageBox(STRING_LENGHT_BYTES_PARAMETER_ERROR);return;
	}

	if(((CButton*)GetDlgItem(IDC_RADIO_USB))->GetCheck())
	{
		OnReadTagUsb();
		return;
	}
	int nCounter = 0;
	int st;
	unsigned char RevData[256]={0};
	unsigned char EPCData26[256]={0};
	unsigned char EPCData34[256]={0};
	unsigned char EPCDisplay[20]={0};
	unsigned char SendData[256]={0};
	unsigned char DataLen,EPCDataLen=12,TagCount;
	BYTE bData[256];
	int m_epcLen = 0;
	char s[256] = {0};
	CString strTmp,str;
	int i,j,linenum;
	int successvalue;
	int num;
	char temp[64]={0};
	unsigned char EPCData[50]={0x5A,0x4B,0x12,0x34,0x55,0x55,0x55,0x55,0x5A,0x4B,0x12,0x34};
	unsigned char EPCData0[50]={0x00};
	int epcdata0len=0;
	unsigned char HexLen[50]={0x00};
	strTmp="";
	str="";
	char temdata[256];
	int epcaddr=0;
	DataLen=16;
	int outlen;//输出长度
	int startaddr;//起点地址
	unsigned char OutIdData[50]={0x00};//输出ID号
	unsigned char Direction=0;


	if ((m_start_byte.GetCurSel()+m_out_len.GetCurSel()+1)>12)	
	{
		MessageBox(STRING_LENGHT_BYTES_PARAMETER_ERROR);return;
	}

	st=UhfReadTag(GlAddresss,RevData,DataLen);
	if(st)return;
	if(GlReaderType==0x02)
	{
		memcpy(EPCData,&RevData[2],12);
		EPCDataLen=DataLen-2;
		if(EPCDataLen==0)return;
	}
	else
	{
		memcpy(EPCData,&RevData[3],12);
		EPCDataLen=DataLen-4;
		if(EPCDataLen==0)return;
	}

	outlen=m_out_len.GetCurSel()+1;
	startaddr=m_start_byte.GetCurSel();

//EPC 输出选择  0 正向，1 反向
//int __stdcall EpcOutput(unsigned char *InputEpc,unsigned char Direction,unsigned char StartAddr,
		//	unsigned char OutputLen,unsigned char *OutputEpc);

	if (((CButton*)GetDlgItem(IDC_RADIO_FORWARD))->GetCheck())Direction=0x00;//forward正
	else Direction=0x01;

	st=EpcOutput(EPCData,EPCDataLen,Direction,startaddr,outlen,OutIdData);
	if(st){MessageBox(STRING_FREQ_ERROR);return;}


/////////////////////////////////////

	CString strtemp;
	CString epcstr;
	strtemp="";
	char asiiepc[50];
	//EPCDataLen=outlen;
	for(i=0;i<outlen;i++)
	{
		epcstr +=IntToASCII(OutIdData[i]);
	}
//__int16 __stdcall hex_a(unsigned char *hex,char *a,unsigned int length);
	hex_a(OutIdData,asiiepc,outlen*2);
	DataLen=outlen;
	linenum = m_List6cID.GetItemCount();
	for(j=0;j<linenum;j++)
	{
		m_List6cID.GetItemText(j, 1,temp, 30);
		strtemp=temp;
		epcdata0len=strlen(temp);
//__int16 __stdcall a_hex(char *a,unsigned char *hex,unsigned int len);	
		a_hex(temp,EPCData0,epcdata0len);
		if(DataLen!=(epcdata0len/2))continue;
		for(i=0;i<DataLen;i++)
		{
			if(OutIdData[i]!=EPCData0[i])break;
		}
		
		if(i==DataLen)
		{
			strTmp=IntToChar(DataLen);
			m_List6cID.SetItemText(linenum, 3, strTmp);//epclen
			m_List6cID.GetItemText(j, 2, temp, 4);//success
			successvalue=CharToInt(temp);
			successvalue++;
			strTmp=IntToChar(successvalue);
			m_List6cID.SetItemText(j, 2, strTmp);
			return;
		}
	}
	m_List6cID.InsertItem(linenum,IntToASCII1BYTED(linenum+1));//插入0 行
	for(i=0;i<DataLen;i++)
	{
	//	str+=strtemp;
	}
	m_List6cID.SetItemText(linenum, 1, epcstr);
	strTmp=IntToChar(EPCDataLen);
	m_List6cID.SetItemText(linenum, 3, strTmp);//epclen
	m_List6cID.GetItemText(linenum, 2, temp, 3);//success
	successvalue=CharToInt(temp);
	successvalue++;
	strTmp=IntToChar(successvalue);
	m_List6cID.SetItemText(j, 2, strTmp);


	return ;

}

void CUhfReaderDlg::OnDblclkListCg(NMHDR* pNMHDR, LRESULT* pResult) 
{

	int ret = MessageBox(STRING_DELETE, STRING_WARNNING, MB_OKCANCEL);
	if (1 == ret)
	{
		m_List6cID.DeleteAllItems();
		m_listTag.clear();
	}
	*pResult = 0;
}

int CUhfReaderDlg::SaveFreqAndPower()
{
	CComboBox *m_MinFrequency	=	(CComboBox*)GetDlgItem(IDC_CB_MINFREQ);
	CComboBox *m_MaxFrequency	=	(CComboBox*)GetDlgItem(IDC_CB_MAXFREQ);
	int imin	=	m_MinFrequency->GetCurSel();
	int imax	=	m_MaxFrequency->GetCurSel();
	if ( imin < 0 )
	{
		imin	=	0;
	}
	if ( imax < 0 )
	{
		imax	=	0;
	}
	//因为通过国家来，每个国家的频率有些不一样的
	basicParam.Min_Frequence = (BYTE)(imin+1);
	basicParam.Max_Frequence = (BYTE)(imax+1);
	//	basicParam.Power = 0;
	CString strPower;
	GetDlgItemText(IDC_EDIT_POWER, strPower);
	basicParam.Power = atoi(strPower);
	unsigned char Parambuffer[100];
	if(basicParam.BaudRate>9)basicParam.BaudRate=8;
	basicParam.WorkMode=1;
	basicParam.EnableBuzzer=1;
	memcpy(Parambuffer,&basicParam, 32);	
	int ret =UhfWriteBasicParam(Parambuffer);
	// ret =UhfReadBasicParam(Parambuffer);//TEST
	 memcpy(&basicParam,Parambuffer, 32);
	if (ret == 0)
	{
//		MessageBox("设置成功");
		return 1;
	}
	return 0;
}
//写参数
void CUhfReaderDlg::OnBtnSave() 
{
	// TODO: Add your control notification handler code here
	unsigned char config[6];
	unsigned char time;
	unsigned char Region;				
	int StartFreq,EndFreq,FreqSpace;
		unsigned char FreqQuantity;
	unsigned char Region2;				
	int StartFreq2,EndFreq2,FreqSpace2;
	unsigned char FreqQuantity2;
	int Freq;
	unsigned char Status;
	int ret,i;
	unsigned char Password[10];
	unsigned char WgOutByteData[4]={0x01,0x00,0x04,0x00};
	unsigned char Value;
	int st;
	unsigned char WorkMode=0;
	CString strSer;
	strSer="";
	m_status_display="";
	UpdateData(true);
	UpdateData(false);
	if((m_wg_time<1)|(m_wg_time>20)){MessageBox(STRING_OUTPUT_TIME_PARAMETER_ERROR);return;}
	//if((m_OutPowerValue<)|(m_OutPowerValue>33)){MessageBox("Power Parameter Error!");return;}
	if((m_OutPowerValue>63)){MessageBox(STRING_POWER_PARAMETER_ERROR);return;}
	//GlReaderType==0x02
	if((m_trigger_time==0)|(m_trigger_time>254)){MessageBox(STRING_READ_TIME_PARAMETER_ERROR);return;}
	//if(m_address>254){MessageBox("Address Parameter Error!");return;}
	if(GlReaderType!=0x02)
	{
		if(m_end_rf.GetCurSel()<m_start_rf.GetCurSel()){MessageBox(STRING_FREQ_ERROR);return;}
	}
	if(((CButton*)GetDlgItem(IDC_RADIO_USB))->GetCheck())//修改于0922
	{
		if (((CButton*)GetDlgItem(IDC_RADIO_WG34))->GetCheck())	
		{
			if(m_start_byte.GetCurSel()>8){MessageBox(STRING_START_BYTES_PARAMETER_ERROR);return;}
		}
		if (((CButton*)GetDlgItem(IDC_RADIO_WG26))->GetCheck())	
		{
			if(m_start_byte.GetCurSel()>9){MessageBox(STRING_START_BYTES_PARAMETER_ERROR);return;}
		}
	}
	else
	{
		if ((m_start_byte.GetCurSel()+m_out_len.GetCurSel()+1)>12)	
		{
			MessageBox(STRING_LENGHT_BYTES_PARAMETER_ERROR);return;
		}
	}


//	if ((m_start_byte.GetCurSel()+m_out_len.GetCurSel()+1)>12)	
//	{
	//	MessageBox("Lenght Bytes Parameter Error!");return;
	//}

	UhfSetWgIntervalTime(GlAddresss,m_wg_time);
	if (((CButton*)GetDlgItem(IDC_CHECK_BUZZER))->GetCheck())
	{
		UhfSetBuzzer(GlAddresss,0x01);
	}
	else
	{
		UhfSetBuzzer(GlAddresss,0x00);
	}
	ret=UhfSetTriggerTime(GlAddresss,m_trigger_time);
	if (((CButton*)GetDlgItem(IDC_RADIO_ALLWAYS))->GetCheck())
	{
		UhfSetWorkMode(GlAddresss,0x00);
	}
	if (((CButton*)GetDlgItem(IDC_RADIO_TRIGGER_READ))->GetCheck())
	{
		UhfSetWorkMode(GlAddresss,0x01);
	}
	WgOutByteData[0]=0x01;//EPC
	WgOutByteData[1]=m_start_byte.GetCurSel();//起点字节
	if (((CButton*)GetDlgItem(IDC_RADIO_FORWARD))->GetCheck())WgOutByteData[3]=0x00;//forward正
	else WgOutByteData[3]=0x01;
/////////////////////////////////////////////////////
	if(((CButton*)GetDlgItem(IDC_RADIO_USB))->GetCheck())
	{

		if (((CButton*)GetDlgItem(IDC_RADIO_WG34))->GetCheck())	
		{
			WgOutByteData[2]=0x04;
			UhfSetWeigand(GlAddresss,0x34);
		}
		else 
		{
			UhfSetWeigand(GlAddresss,0x26);
			WgOutByteData[2]=0x03;
		}

	}
	else
	{
		WgOutByteData[2]=m_out_len.GetCurSel()+1;//长度
	}
	ret=UhfSetWgOutByte(GlAddresss,WgOutByteData);
	if(ret)
	{
		MessageBox(STRING_SET_WIEGAND_OUTPUT_SETTINGS_FAIL);
		return ;
	}
	ret=UhfSetWgIntervalTime(GlAddresss,m_wg_time);
	strSer="";
	__int16 len = m_password.GetLength();          													
	for(i = 0; i < len; i = i + 2)		 //写卡编辑框的三个字符对应卡的一个字节		
	{
		CString temp = m_password.Mid(i, 2);	 //两个字符两个字符地取
		StrToHex(temp,1,&Password[i / 2]);		 //转换为16进制数	 //转换为16进制数
	}
	if(((CButton*)GetDlgItem(IDC_RADIO_YES))->GetCheck())
	{
		st= UhfSetPassword(GlAddresss,1,Password);
	}
	if (((CButton*)GetDlgItem(IDC_RADIO_NO))->GetCheck())
	{
		st= UhfSetPassword(GlAddresss,0,Password);
	}
	ret=UhfSetAddress(GlAddresss,m_address);
	if(ret)
	{
		MessageBox(STRING_SET_ADDRESS_FAIL);
		return ;
	}
	st=UhfSetReadTagIntervalTime(GlAddresss,m_readcard_delaytime);
	if(GlReaderType==0x02)
	{
		Region=0x05;
		StartFreq=m_start_rf.GetCurSel()+1;
		EndFreq=m_end_rf.GetCurSel()+1;
		ret=UhfSetFrequencyRegion(GlAddresss,Region,StartFreq,EndFreq,
				 FreqSpace,FreqQuantity);
		if(ret)
		{
			MessageBox(STRING_GET_FREQUENCY_REGION_FAIL);
			return ;
		}
		ret=UhfSetOutPower(GlAddresss,m_power.GetCurSel());
		if(ret)
		{
			MessageBox(STRING_SET_OUTPOWER_FAIL);
			return ;
		}
	}
	else
	{
	//   500 KHZ 为一个Space 
	//	if(m_end_rf.GetCurSel()<m_start_rf.GetCurSel()){MessageBox("Freq Error!");return;}
	//	FreqQuantity=m_end_rf.GetCurSel()-m_start_rf.GetCurSel();
	//   StartFreq=902000+500*(m_start_rf.GetCurSel());
	//	EndFreq=902000+500*(m_end_rf.GetCurSel());
	//  FreqSpace=500;
	//  Region=0x04;
		if(m_end_rf.GetCurSel()<m_start_rf.GetCurSel()){MessageBox(STRING_FREQ_ERROR);return;}


		if(((CButton*)GetDlgItem(IDC_RADIO_FCC))->GetCheck())
		{
			/////////////////////美标///////////////////////////////////
			FreqQuantity=m_end_rf.GetCurSel()-m_start_rf.GetCurSel();
			StartFreq=902000+500*(m_start_rf.GetCurSel());
			EndFreq=902000+500*(m_end_rf.GetCurSel());
			FreqSpace=500;
			Region=0x04;
		}
		else
		{
			/////////////////////欧标///////////////////////////////////
			if(m_end_rf.GetCurSel()>6){MessageBox(STRING_FREQ_ERROR);return;}
			FreqQuantity=m_end_rf.GetCurSel()-m_start_rf.GetCurSel();
			StartFreq=865000+500*(m_start_rf.GetCurSel());
			EndFreq=865000+500*(m_end_rf.GetCurSel());
			FreqSpace=500;
			Region=0x04;
		}
		ret=UhfSetFrequencyRegion(GlAddresss,Region,StartFreq,EndFreq,
					 FreqSpace,FreqQuantity);
		if(ret)
		{
			MessageBox(STRING_GET_FREQUENCY_REGION_FAIL);
			return ;
		}
		if(GlReaderType==0x01)
		{
			ret=UhfSetOutPower(GlAddresss,m_power.GetCurSel()+18);	
		}
		if(GlReaderType==0x00)
		{
			ret=UhfSetOutPower(GlAddresss,m_power.GetCurSel());	
		}
		if(ret)
		{
			MessageBox(STRING_SET_OUTPOWER_FAIL);
			return ;
		}
	}
	m_status_display=STRING_SAVED;
	UpdateData(false);

}

int CUhfReaderDlg::SetTime()
{
	return 0;
}

int CUhfReaderDlg::SetBaud()
{
	unsigned char baud = 0;
	switch (m_cbBaud.GetCurSel())
	{
	case 0:
		baud = 4;
		break;
	case 1:
		baud = 5;
		break;
	case 2:
		baud = 6;
		break;
	case 3:
		baud = 7;
		break;
	case 4:
		baud = 8;
		break;
	default:
		baud = 4;
		break;
	}
	int ret = UhfSetBaudRate(GlAddresss,baud);
	if (ret == 0)
	{
//		MessageBox("设置成功");
		return 1;
	}
	return 0;
}

int CUhfReaderDlg::SetWeigand()
{
	unsigned char wg = 0x26;
	/*
	switch (m_cbWg.GetCurSel())
	{
	case 0:
		wg = 0x26;
		break;
	case 1:
		wg = 0x34;
		break;
	default:
		wg = 0x26;
		break;
	}
	*/
	int ret = UhfSetWeigand(GlAddresss,wg);
	if (ret == 0)
	{
//		MessageBox("设置成功");
		return 1;
	}
	return 0;
}

int CUhfReaderDlg::SetBuzzerLed()
{
	unsigned char onoff = 0;
	if (((CButton*)GetDlgItem(IDC_CHECK_LED))->GetCheck())
	{
		onoff += 0x10;
	}
	if (((CButton*)GetDlgItem(IDC_CHECK_BUZZER))->GetCheck())
	{
		onoff += 0x1;
	}
	int ret = UhfSetBuzzer(GlAddresss,onoff);
	if (ret == 0)
	{
//		MessageBox("设置成功");
		return 1;
	}
	return 0;
}

int CUhfReaderDlg::SetWorkMode()
{
	unsigned char mode = 0;
	if (((CButton*)GetDlgItem(IDC_RADIO_ALLWAYS))->GetCheck())
	{
		mode = MODE_ALLWAYS_READ;
	}
	if (((CButton*)GetDlgItem(IDC_RADIO_TRIGGER_READ))->GetCheck())
	{
		mode = MODE_TRIGGER_READ;
	}
	int ret = UhfSetWorkMode(GlAddresss,mode);
	if (ret == 0)
	{
		//MessageBox("设置成功");
		if (mode == 1)
			EnableAllButton(FALSE);
		return 1;
	}
	return 0;
}

void CUhfReaderDlg::OnReadConfig() 
{
	// TODO: Add your control notification handler code here
	unsigned char config[6];
	unsigned char WgOutByteData[100];
	unsigned char time;
	unsigned char Region;				
	int StartFreq,EndFreq,FreqSpace;
	unsigned char FreqQuantity;
	int Freq;
	unsigned char Status;
	unsigned char Password[4];
	unsigned char Value,wvalue,svalue;
	int ret,i;
	unsigned char workmode=0;
	CString strSer;
	int m=0;
	strSer="";
	m_status_display="";
	//UpdateData(false);
	UpdateData(true);
	UhfGetBuzzer(GlAddresss,Value);
	if (Value ==0x00)
	{
		((CButton*)GetDlgItem(IDC_CHECK_BUZZER))->SetCheck(FALSE);
	}
	else
	{
		((CButton*)GetDlgItem(IDC_CHECK_BUZZER))->SetCheck(TRUE);
	}
	ret=UhfGetTriggerTime(GlAddresss,Value);//2
	m_trigger_time=Value;
		UpdateData(false);
	//工作模式
	UhfGetWorkMode(GlAddresss,workmode);
	if (workmode == 0x01)
	{
		((CButton*)GetDlgItem(IDC_RADIO_ALLWAYS))->SetCheck(FALSE);
		((CButton*)GetDlgItem(IDC_RADIO_TRIGGER_READ))->SetCheck(TRUE);
		GetDlgItem(IDC_EDIT_TRIGGER_TIME)->EnableWindow(TRUE);
	}
	else
	{
		((CButton*)GetDlgItem(IDC_RADIO_TRIGGER_READ))->SetCheck(FALSE);
		((CButton*)GetDlgItem(IDC_RADIO_ALLWAYS))->SetCheck(TRUE);
	   	GetDlgItem(IDC_EDIT_TRIGGER_TIME)->EnableWindow(FALSE);
	}
	
	ret =UhfGetWgOutByte(GlAddresss,WgOutByteData);
	if(ret)
	{
		MessageBox(STRING_SET_WIEGAND_OUTPUT_SETTINGS_FAIL);
		return ;
	}
	if (WgOutByteData[3] ==0)
	{
		((CButton*)GetDlgItem(IDC_RADIO_FORWARD))->SetCheck(TRUE);
		((CButton*)GetDlgItem(IDC_RADIO_INVERTED))->SetCheck(FALSE);
	}
	else
	{
		((CButton*)GetDlgItem(IDC_RADIO_INVERTED))->SetCheck(TRUE);
		((CButton*)GetDlgItem(IDC_RADIO_FORWARD))->SetCheck(FALSE);
	}



	CString str;
	m_start_byte.ResetContent();
	m=0;
	for(i=0; i<12; i++)
	{	
		str.Format("%d",m);
		m_start_byte.AddString(str);
		m=m+1;
	}
	m_start_byte.SetCurSel(WgOutByteData[1]);



	if(((CButton*)GetDlgItem(IDC_RADIO_USB))->GetCheck())
	{
		ret =UhfGetWeigand(GlAddresss,svalue);
		if (svalue == 0x26)
		{
			((CButton*)GetDlgItem(IDC_RADIO_WG26))->SetCheck(TRUE);
			((CButton*)GetDlgItem(IDC_RADIO_WG34))->SetCheck(FALSE);
		}
		else if (svalue == 0x34)
		{
			((CButton*)GetDlgItem(IDC_RADIO_WG34))->SetCheck(TRUE);
			((CButton*)GetDlgItem(IDC_RADIO_WG26))->SetCheck(FALSE);
		}

	}
	else
	{

		m_out_len.SetCurSel(WgOutByteData[2]-1);
	}

	int st;
	//st=UhfGetPasswordByteCheck(GlAddresss,&Status);
	st= UhfGetPassword(GlAddresss,Status,Password);
	if(Status)
	{
		((CButton*)GetDlgItem(IDC_RADIO_YES))->SetCheck(TRUE);
		((CButton*)GetDlgItem(IDC_RADIO_NO))->SetCheck(FALSE);
	}
	else
	{
		((CButton*)GetDlgItem(IDC_RADIO_YES))->SetCheck(FALSE);
		((CButton*)GetDlgItem(IDC_RADIO_NO))->SetCheck(TRUE);
	}
	strSer="";
	for( i = 0;i<4;i++)
	{
		strSer +=IntToASCII(Password[i]);
	}
	m_password=strSer;
	SetDlgItemText(IDC_EDIT_PASSWORD, strSer);
	st=UhfGetReadTagIntervalTime(GlAddresss,Value);//1
	strSer.Format("%d",Value);
	SetDlgItemText(IDC_EDIT_READCARD_DELAYTIME, strSer);

	ret = UhfGetWgIntervalTime(GlAddresss,time);//1
	m_wg_time=time;//2


	ret=UhfGetFrequencyRegion(GlAddresss,Region,StartFreq,EndFreq,
					 FreqSpace,FreqQuantity);
	if(ret)
	{
		MessageBox(STRING_SET_FREQUENCY_REGION_FAIL);
		return ;
	}
	if(GlReaderType==0x02)
	{
		

		BYTE imin	=	StartFreq-1;
		BYTE imax	=	EndFreq-1;
		m_bFre=0;//只支持美标
		OnCbnSetFre(m_bFre, imin, imax);//因为通过国家来，每个国家的频率有些不一样的
		UpdateData(false);
	
	}
	else
	{

		//罗丹贝尔模块

		CString str;

		if(StartFreq>=902000)///////////////
		{

			m_start_rf.ResetContent();
			/////////////////////////////美标///////////////////////
			m=902000;
			for(i=0; i<53; i++)
			{	
				str.Format("%d",m);
				m_start_rf.AddString(str);
				m=m+500;
			}
			m_end_rf.ResetContent();
			m=902000;
			for(i=0; i<53; i++)
			{	
				str.Format("%d",m);
				m_end_rf.AddString(str);
				m=m+500;
			}

			m_start_rf.SetCurSel(((StartFreq-902000)/500));
			m_end_rf.SetCurSel(((StartFreq-902000)/500)+FreqQuantity);
		}
		else
		{

	/////////////////////////欧标////////////////////////////////////
			m_start_rf.ResetContent();
			m=865000;
			for(i=0; i<7; i++)
			{	
				str.Format("%d",m);
				m_start_rf.AddString(str);
				m=m+500;
			}
			//m_start_rf.SetCurSel(0);

			m=865000;
			m_end_rf.ResetContent();
			for(i=0; i<7; i++)
			{	
				str.Format("%d",m);
				m_end_rf.AddString(str);
				m=m+500;
			}
			m_start_rf.SetCurSel(((StartFreq-865000)/500));
			m_end_rf.SetCurSel(((StartFreq-865000)/500)+FreqQuantity);	
		
		}
	}
	ret=UhfGetAddress(GlAddresss,Value);
	if(ret)
	{
		MessageBox(STRING_GET_ADDRESS_FAIL);
		return ;
	}
	m_address=Value;
	ret=UhfGetOutPower(GlAddresss,Value);
	if(ret)
	{
		MessageBox(STRING_SET_OUTPOWER_FAIL);
		return ;
	}
	//m_OutPowerValue=Value;


	//GlReaderType=2;
	if(GlReaderType==0x02)
	{

		m=0;
		m_power.ResetContent();
		for(i=0; i<64; i++)
		{	
			str.Format("%d",m);
			m_power.AddString(str);
			m=m+1;
		}
		m_power.SetCurSel(Value);
		UpdateData(false);
	}
	if(GlReaderType==0x01)
	{
		m=18;
		m_power.ResetContent();
		for(i=0; i<9; i++)
		{	
			str.Format("%d",m);
			m_power.AddString(str);
			m=m+1;
		}
		m_power.SetCurSel((Value-18));
		UpdateData(false);

	}
	if(GlReaderType==0x00)
	{
		m=0;//read power
		m_power.ResetContent();
		for(i=0; i<34; i++)
		{	
			str.Format("%d",m);
			m_power.AddString(str);
			m=m+1;
		}
		m_power.SetCurSel((Value));
		UpdateData(false);

	}


	m_status_display=STRING_READ_CONFIGURATION_OK;
	UpdateData(false);
	return ;
}

void CUhfReaderDlg::OnRadioAllways() 
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_EDIT_TRIGGER_TIME)->EnableWindow(FALSE);
}

void CUhfReaderDlg::OnRadioTriggerRead() 
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_EDIT_TRIGGER_TIME)->EnableWindow(TRUE);
}

int CUhfReaderDlg::SetTriggerMode()
{
	int ret = UhfSetWorkMode(GlAddresss,0);
	if (ret == 0)
	{
		//		MessageBox("设置成功");
		return 1;
	}
	return 0;
}

int CUhfReaderDlg::SaveWeigand()
{
	unsigned char wg = 0x26;
	
	if (((CButton*)GetDlgItem(IDC_RADIO_WG26))->GetCheck())
		wg = 0x26;

	if (((CButton*)GetDlgItem(IDC_RADIO_WG34))->GetCheck())
		wg = 0x34;

	int ret =UhfSetWeigand(GlAddresss,wg);
	if (ret == 0)
	{
//		MessageBox("设置成功");
		if (wg == 0x26)
			m_wg34 = FALSE;
		else
			m_wg34 = TRUE;
		return 1;
	}
	return 0;
}

int CUhfReaderDlg::UhfReadConfig()
{
	unsigned char config[6];
	//F0 07 FA 波特率,时间,WG格式,蜂鸣器,工作模式
	/*
	if (0 == SetWorkMode())
	{
		return ;
	}
	*/
	//int ret = UhfGetConfig(GlAddresss,config);
	//if (ret != 0)
	//{
	//	return 1;
	//}
	unsigned char Parambuffer[100];
	//if (0 ==UhfGetFrequencyRange(GlAddresss,&m_bFre))
	if(1)
	{
		if (0 == UhfReadBasicParam(Parambuffer))
		{
			memcpy(&basicParam,Parambuffer, 32);

			BYTE imin	=	basicParam.Min_Frequence-1;
			BYTE imax	=	basicParam.Max_Frequence-1;
			/*
			CComboBox *m_MinFrequency	=	(CComboBox*)GetDlgItem(IDC_CB_MINFREQ);
			CComboBox *m_MaxFrequency	=	(CComboBox*)GetDlgItem(IDC_CB_MAXFREQ);

			if ( imin < 0 )
			{
				imin	=	0;
			}
			if ( imax < 0 )
			{
				imax	=	0;
			}
			//因为通过国家来，每个国家的频率有些不一样的
			basicParam.Min_Frequence = (BYTE)(imin+1);
			basicParam.Max_Frequence = (BYTE)(imax+1);
			*/
			
			OnCbnSetFre(m_bFre, imin, imax);//因为通过国家来，每个国家的频率有些不一样的

			CString strPower;
			strPower.Format("%d", basicParam.Power);
			SetDlgItemText(IDC_EDIT_POWER, strPower);
		}
		else
		{
			return 2;
		}
	}
	else
	{
		return 3;
	}
	char szTmp[5] = {0};
	return 0;
}

void CUhfReaderDlg::EnableAllButton(BOOL bEnable)
{
	GetDlgItem(IDC_READ_CONFIG)->EnableWindow(bEnable);
	GetDlgItem(IDC_BTN_SETDEFAULT)->EnableWindow(bEnable);
	GetDlgItem(IDC_BTN_SAVE)->EnableWindow(bEnable);
	GetDlgItem(IDC_BTN_READTAG)->EnableWindow(bEnable);
}

BOOL CUhfReaderDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (pMsg->message == WM_CHAR)
	{

	}
	return CDialog::PreTranslateMessage(pMsg);
}



void CUhfReaderDlg::OnChangeEditReadcardDelaytime() 
{
	UpdateData(true);
	
}

void CUhfReaderDlg::OnChangeEditWgOutByte() 
{

	UpdateData(true);
	UpdateData(false);
	
}

HBRUSH CUhfReaderDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

 if(nCtlColor==CTLCOLOR_BTN)          //更改按钮颜色
 {
  //pDC->SetBkMode(TRANSPARENT);
 // pDC->SetTextColor(RGB(0,0,0));
 // pDC->SetBkColor(RGB(0,0,0));   
  //HBRUSH b=CreateSolidBrush(RGB(154,205,50));
    HBRUSH b=CreateSolidBrush(RGB(255,255,255));
  return b;
 }
 else if(nCtlColor==CTLCOLOR_SCROLLBAR)  //
 {
  //pDC->SetBkMode(TRANSPARENT);
  pDC->SetTextColor(RGB(0,0,0));
  pDC->SetBkColor(RGB(233,233,220));
  HBRUSH b=CreateSolidBrush(RGB(233,233,220));
  return b;
 }
 else if(nCtlColor==CTLCOLOR_EDIT)   //更改编辑框
 {
  //pDC->SetBkMode(TRANSPARENT);
  pDC->SetTextColor(RGB(0,0,0));
  pDC->SetBkColor(RGB(255,255,255));
  HBRUSH b=CreateSolidBrush(RGB(255,255,255));
  return b;
 }
 else if(nCtlColor==CTLCOLOR_STATIC)  //更改静态文本
 {
  pDC->SetTextColor(RGB(255,255,255));
  pDC->SetBkColor(RGB(92,92,92));
  HBRUSH b=CreateSolidBrush(RGB(92,92,92));
  return b;
 }
 else if(nCtlColor==CTLCOLOR_DLG)   //更改对话框背景色
 {
  pDC->SetTextColor(RGB(0,0,0));
  pDC->SetBkColor(RGB(92,92,92));
  HBRUSH b=CreateSolidBrush(RGB(88,93,99));
//154 205 50
  return b;
 }
	
	return hbr;
}

void CUhfReaderDlg::OnSettingAddress() 
{
	unsigned char Value;
	int ret;	
	UpdateData(true);
	ret=UhfSetAddress(GlAddresss,m_address);
	if(ret)
	{
		MessageBox(STRING_SET_ADDRESS_FAIL);
		return ;
	}
	//m_address=Value;
	UpdateData(false);
}

void CUhfReaderDlg::OnGetAddress() 
{

	unsigned char Value;
	unsigned char Version[30]={0x00};
	int ret;
	UpdateData(true);
	Get_Version(GlAddresss,Version);
	m_version=Version;

	ret=UhfGetAddress(GlAddresss,Value);
	if(ret)
	{
		MessageBox(STRING_SET_ADDRESS_FAIL);
		return ;
	}
	m_address=Value;

	UpdateData(false);
}

void CUhfReaderDlg::OnReadTag2() 
{
	// TODO: Add your control notification handler code here
	int nCounter = 0;
	int st;
	unsigned char RevData[256]={0};
//	unsigned char EPCData[256]={0};
	unsigned char EPCData26[256]={0};
	unsigned char EPCData34[256]={0};
	unsigned char EPCDisplay[20]={0};
	unsigned char SendData[256]={0};
	unsigned char DataLen,EPCDataLen,TagCount;
	BYTE bData[256];
	int m_epcLen = 0;
	char s[256] = {0};
	CString strTmp,str;
	int i,j,linenum;
	int successvalue;
	int num;
	char temp[64]={0};
	//unsigned char EPCData[50]={0x00};
	unsigned char EPCData[50]={0x5A,0x4B,0x12,0x34,0x55,0x55,0x55,0x55,0x5A,0x4B,0x12,0x34};
	unsigned char EPCData0[50]={0x00};
	int epcdata0len=0;
	unsigned char HexLen[50]={0x00};
//	DataLen=12;
//	st=0;
	DataLen=16;
	st=UhfReadTag(GlAddresss,RevData,DataLen);
//////////////////////////TEST
//////////////////////////TEST
	memcpy(EPCData,&RevData[3],12);
//	m_List6cID.DeleteAllItems();
	strTmp="";
	str="";
	char temdata[256];
	int epcaddr=0;
	EPCDataLen=DataLen-4;
	if(EPCDataLen==0)return;
	if (((CButton*)GetDlgItem(IDC_RADIO_WG34))->GetCheck())	
	{
		if((m_start_byte.GetCurSel()+4)>EPCDataLen)return;		
	}
	else
	{
		if((m_start_byte.GetCurSel()+3)>EPCDataLen)return;
	}
	if(EPCDataLen>20)return;
	epcaddr=m_start_byte.GetCurSel();
	//正向输出
	if (((CButton*)GetDlgItem(IDC_RADIO_FORWARD))->GetCheck())
	{
		if (((CButton*)GetDlgItem(IDC_RADIO_WG34))->GetCheck())	
		{	
			EPCData34[0]=EPCData[epcaddr];
			EPCData34[1]=EPCData[epcaddr+1];
			EPCData34[2]=EPCData[epcaddr+2];
			EPCData34[3]=EPCData[epcaddr+3];
			sprintf(temdata,"%010u", htonl(*(unsigned long*)EPCData34));
			DataLen=10;
		}
		else
		{				
			EPCData26[0]=0;
			EPCData26[1]=EPCData[epcaddr];
			EPCData26[2]=EPCData[epcaddr+1];
			EPCData26[3]=EPCData[epcaddr+2];
			sprintf(temdata,"%008u", htonl(*(unsigned long*)EPCData26));
			DataLen=8;
		}
	}
	else
	{
		if (((CButton*)GetDlgItem(IDC_RADIO_WG34))->GetCheck())	
		{	
			EPCData34[0]=EPCData[epcaddr+3];
			EPCData34[1]=EPCData[epcaddr+2];
			EPCData34[2]=EPCData[epcaddr+1];
			EPCData34[3]=EPCData[epcaddr];
			sprintf(temdata,"%010u", htonl(*(unsigned long*)EPCData34));
			DataLen=10;
		}
		else
		{				
			EPCData26[0]=0;
			EPCData26[1]=EPCData[epcaddr];
			EPCData26[2]=EPCData[epcaddr+1];
			EPCData26[3]=EPCData[epcaddr+2];
			sprintf(temdata,"%008u", htonl(*(unsigned long*)EPCData26));
			DataLen=8;
		}
	}
	linenum = m_List6cID.GetItemCount();
	for(j=0;j<linenum;j++)
	{
	//  m_List6cID.GetItemText(j, 4, temp, 4);
	//	a_hex(temp,HexLen,4);
	//	epcdata0len=HexLen[0];
		m_List6cID.GetItemText(j, 1, temp, 30);
		epcdata0len=strlen(temp);
	//	a_hex(temp,EPCData0,40);
		//if(DataLen!=epcdata0len)break;
		for(i=0;i<DataLen;i++)
		{
			if(temdata[i]!=temp[i])break;
		}
		if(i==DataLen)
		{
			strTmp=IntToChar(DataLen);
			m_List6cID.SetItemText(linenum, 4, strTmp);//epclen
			m_List6cID.GetItemText(j, 2, temp, 4);//success
			successvalue=CharToInt(temp);
			successvalue++;
			strTmp=IntToChar(successvalue);
			m_List6cID.SetItemText(j, 2, strTmp);
			return;
		}
	}
	m_List6cID.InsertItem(linenum,IntToASCII1BYTED(linenum+1));//插入0 行
//	for(i=0;i<EPCDataLen;i++)
//	{
//		str+=IntToASCII(EPCData[i]);
//	}
	for(i=0;i<DataLen;i++)
	{
		str+=temdata[i];
	}
	m_List6cID.SetItemText(linenum, 1, str);
	strTmp=IntToChar(EPCDataLen);
	m_List6cID.SetItemText(linenum, 4, strTmp);//epclen
	m_List6cID.GetItemText(linenum, 2, temp, 3);//success
	successvalue=CharToInt(temp);
	successvalue++;
	strTmp=IntToChar(successvalue);
	m_List6cID.SetItemText(j, 2, strTmp);
	return ;
	
	
}

void CUhfReaderDlg::OnReadTag16() 
{

		// TODO: Add your control notification handler code here
	int nCounter = 0;
	int st;
	unsigned char RevData[256]={0};
//	unsigned char EPCData[256]={0};
	unsigned char EPCData26[256]={0};
	unsigned char EPCData34[256]={0};
	unsigned char EPCDisplay[20]={0};
	unsigned char SendData[256]={0};
	unsigned char DataLen,EPCDataLen,TagCount;
	BYTE bData[256];
	int m_epcLen = 0;
	char s[256] = {0};
	CString strTmp,str;
	int i,j,linenum;
	int successvalue;
	int num;
	char temp[64]={0};
	unsigned char EPCData[50]={0x00};
	unsigned char EPCData0[50]={0x00};
	int epcdata0len=0;
	unsigned char HexLen[50]={0x00};
//	DataLen=12;
	st=UhfReadTag(GlAddresss,RevData,DataLen);
	if(st)return;
	memcpy(EPCData,&RevData[3],12);

//	m_List6cID.DeleteAllItems();
	strTmp="";
	str="";
	char temdata[256];
	int epcaddr=0;
	EPCDataLen=DataLen-4;
	if(EPCDataLen==0)return;
	if(EPCDataLen>20)return;
/*
	//正向输出
	if (((CButton*)GetDlgItem(IDC_RADIO_FORWARD))->GetCheck())
	{
		if(m_wg34)
		{	
			EPCData34[0]=EPCData[epcaddr+2];
			EPCData34[1]=EPCData[epcaddr+1];
			EPCData34[2]=EPCData[epcaddr];
			EPCData34[3]=EPCData[epcaddr-1];
			sprintf(temdata,"%010u", htonl(*(unsigned long*)EPCData34));
		}
		else
		{				
			EPCData26[0]=0;
			EPCData26[1]=EPCData[epcaddr+2];
			EPCData26[2]=EPCData[epcaddr+1];
			EPCData26[3]=EPCData[epcaddr];
			sprintf(temdata,"%008u", htonl(*(unsigned long*)EPCData26));
		}
	}
*/
	linenum = m_List6cID.GetItemCount();
	for(j=0;j<linenum;j++)
	{
		m_List6cID.GetItemText(j, 4, temp, 4);
//__int16 __stdcall a_hex(char *a,unsigned char *hex,unsigned int len);
		//a_hex(temp,HexLen,4);
		if(strlen(temp)==1)
			epcdata0len=(unsigned char)temp[0]-0x30;
	if(strlen(temp)==2)
			epcdata0len=((unsigned char)temp[0]-0x30)*10+(unsigned char)temp[1]-0x30;

		if(epcdata0len!=EPCDataLen)continue;
	
		m_List6cID.GetItemText(j, 1, temp, 40);
		a_hex(temp,EPCData0,40);
	
		for(i=0;i<epcdata0len;i++)
		{
			if(EPCData[i]!=EPCData0[i])break;
		}
	
		if(i==epcdata0len)
		{
			strTmp=IntToChar(DataLen);
			m_List6cID.SetItemText(linenum, 4, strTmp);//epclen
			m_List6cID.GetItemText(j, 2, temp, 4);//success
			successvalue=CharToInt(temp);
			successvalue++;
			strTmp=IntToChar(successvalue);
			m_List6cID.SetItemText(j, 2, strTmp);
			return;
		}
	}

	m_List6cID.InsertItem(linenum,IntToASCII1BYTED(linenum+1));//插入0 行
	for(i=0;i<EPCDataLen;i++)
	{
		str+=IntToASCII(EPCData[i]);
	}
	m_List6cID.SetItemText(linenum, 1, str);
	strTmp=IntToChar(EPCDataLen);
	m_List6cID.SetItemText(linenum, 4, strTmp);//epclen
	m_List6cID.GetItemText(linenum, 2, temp, 3);//success
	successvalue=CharToInt(temp);
	successvalue++;
	strTmp=IntToChar(successvalue);
	m_List6cID.SetItemText(j, 2, strTmp);

	return ;




	
}


void CUhfReaderDlg::OnRadioFcc() 
{

	
	CString str;
	int m=902000;
	int i;
	m_start_rf.ResetContent();
	for(i=0; i<53; i++)
	{	
		str.Format("%d",m);
		m_start_rf.AddString(str);
		m=m+500;
	}
	m_start_rf.SetCurSel(0);

	m=902000;
	m_end_rf.ResetContent();
	for(i=0; i<53; i++)
	{	
		str.Format("%d",m);
		m_end_rf.AddString(str);
		m=m+500;
	}
	m_end_rf.SetCurSel(30);



}

void CUhfReaderDlg::OnRadioEtsi() 
{
	CString str;
	int m=860000;
	int i;
	m_start_rf.ResetContent();
	for(i=0; i<7; i++)
	{	
		str.Format("%d",m);
		m_start_rf.AddString(str);
		m=m+500;
	}
	m_start_rf.SetCurSel(0);

	m=860000;
	m_end_rf.ResetContent();
	for(i=0; i<7; i++)
	{	
		str.Format("%d",m);
		m_end_rf.AddString(str);
		m=m+500;
	}
	m_end_rf.SetCurSel(3);	
	
}

void CUhfReaderDlg::OnRadioWg26() 
{

	int m=0;
	int i;
	CString str="";

	m_start_byte.ResetContent();
	m=0;
	for(i=0; i<10; i++)
	{	
		str.Format("%d",m);
		m_start_byte.AddString(str);
		m=m+1;
	}
	m_start_byte.SetCurSel(0);


}

void CUhfReaderDlg::OnRadioWg34() 
{

	int m=0;
	int i;
	CString str="";

	m_start_byte.ResetContent();
	m=0;
	for(i=0; i<9; i++)
	{	
		str.Format("%d",m);
		m_start_byte.AddString(str);
		m=m+1;
	}
	m_start_byte.SetCurSel(0);	


}

void CUhfReaderDlg::OnReadTagUsb() 
{
	// TODO: Add your control notification handler code here
	int nCounter = 0;
	int st;
	unsigned char RevData[256]={0};
	unsigned char EPCData26[256]={0};
	unsigned char EPCData34[256]={0};
	unsigned char EPCDisplay[20]={0};
	unsigned char SendData[256]={0};
	unsigned char DataLen,EPCDataLen,TagCount;
	BYTE bData[256];
	int m_epcLen = 0;
	char s[256] = {0};
	CString strTmp,str;
	int i,j,linenum;
	int successvalue;
	int num;
	char temp[64]={0};
	unsigned char EPCData[50]={0x5A,0x4B,0x12,0x34,0x55,0x55,0x55,0x55,0x5A,0x4B,0x12,0x34};
	unsigned char EPCData0[50]={0x00};
	int epcdata0len=0;
	unsigned char HexLen[50]={0x00};
	strTmp="";
	str="";
	char temdata[256];
	int epcaddr=0;
	DataLen=16;
	st=UhfReadTag(GlAddresss,RevData,DataLen);
	if(st)return;
//////////////////////////////////////////////TEST
	if(GlReaderType==0x02)
	{
		memcpy(EPCData,&RevData[2],12);
		EPCDataLen=DataLen-2;
		if(EPCDataLen==0)return;
	}
	else
	{
		memcpy(EPCData,&RevData[3],12);
		EPCDataLen=DataLen-4;
		if(EPCDataLen==0)return;
	}
////////////////////////////////////////////////////////////////
	if (((CButton*)GetDlgItem(IDC_RADIO_WG34))->GetCheck())	
	{
		if((m_start_byte.GetCurSel()+4)>EPCDataLen)return;
	}
	else
	{
		if((m_start_byte.GetCurSel()+3)>EPCDataLen)return;
	}
	if(EPCDataLen>20)return;
	/////////////////////////////////////////////////////////////////
	epcaddr=m_start_byte.GetCurSel();
	if (((CButton*)GetDlgItem(IDC_RADIO_FORWARD))->GetCheck())
	{
		if (((CButton*)GetDlgItem(IDC_RADIO_WG34))->GetCheck())	
		{	
			EPCData34[0]=EPCData[epcaddr];
			EPCData34[1]=EPCData[epcaddr+1];
			EPCData34[2]=EPCData[epcaddr+2];
			EPCData34[3]=EPCData[epcaddr+3];
			sprintf(temdata,"%010u", htonl(*(unsigned long*)EPCData34));
			DataLen=10;
		}
		else
		{				
			EPCData26[0]=0;
			EPCData26[1]=EPCData[epcaddr];
			EPCData26[2]=EPCData[epcaddr+1];
			EPCData26[3]=EPCData[epcaddr+2];
			sprintf(temdata,"%008u", htonl(*(unsigned long*)EPCData26));
			DataLen=8;
		}
	}
	else
	{
		if (((CButton*)GetDlgItem(IDC_RADIO_WG34))->GetCheck())	
		{	
			EPCData34[0]=EPCData[epcaddr+3];
			EPCData34[1]=EPCData[epcaddr+2];
			EPCData34[2]=EPCData[epcaddr+1];
			EPCData34[3]=EPCData[epcaddr];
			sprintf(temdata,"%010u", htonl(*(unsigned long*)EPCData34));
			DataLen=10;
		}
		else
		{				
			EPCData26[0]=0;
			EPCData26[1]=EPCData[epcaddr+2];
			EPCData26[2]=EPCData[epcaddr+1];
			EPCData26[3]=EPCData[epcaddr];
			sprintf(temdata,"%008u", htonl(*(unsigned long*)EPCData26));
			DataLen=8;
		}
	}
	linenum = m_List6cID.GetItemCount();
	for(j=0;j<linenum;j++)
	{
		m_List6cID.GetItemText(j, 1,temp, 30);
		epcdata0len=strlen(temp);	
		for(i=0;i<DataLen;i++)
		{
			if(temdata[i]!=temp[i])break;
		}
		if(i==DataLen)
		{
			strTmp=IntToChar(DataLen);
			m_List6cID.SetItemText(linenum, 3, strTmp);//epclen
			m_List6cID.GetItemText(j, 2, temp, 4);//success
			successvalue=CharToInt(temp);
			successvalue++;
			strTmp=IntToChar(successvalue);
			m_List6cID.SetItemText(j, 2, strTmp);
			return;
		}
	}
	m_List6cID.InsertItem(linenum,IntToASCII1BYTED(linenum+1));//插入0 行
	//	for(i=0;i<EPCDataLen;i++)
	//	{
	//		str+=IntToASCII(EPCData[i]);
	//	}

	for(i=0;i<DataLen;i++)
	{
		str+=temdata[i];
	}
	m_List6cID.SetItemText(linenum, 1, str);
	strTmp=IntToChar(EPCDataLen);
	m_List6cID.SetItemText(linenum, 3, strTmp);//epclen
	m_List6cID.GetItemText(linenum, 2, temp, 3);//success
	successvalue=CharToInt(temp);
	successvalue++;
	strTmp=IntToChar(successvalue);
	m_List6cID.SetItemText(j, 2, strTmp);
	return ;

}

void CUhfReaderDlg::OnRadioUsb() 
{

	GetDlgItem(IDC_COMBO_OUT_LEN)->EnableWindow(FALSE);	
	GetDlgItem(IDC_RADIO_WG34)->EnableWindow(true);	
	GetDlgItem(IDC_RADIO_WG26)->EnableWindow(true);		

	
}

void CUhfReaderDlg::OnRadioCom() 
{

	GetDlgItem(IDC_COMBO_OUT_LEN)->EnableWindow(true);
	GetDlgItem(IDC_RADIO_WG34)->EnableWindow(false);	
	GetDlgItem(IDC_RADIO_WG26)->EnableWindow(false);			
}

void CUhfReaderDlg::OnRadioTcp() 
{
	
	GetDlgItem(IDC_COMBO_OUT_LEN)->EnableWindow(true);
	GetDlgItem(IDC_RADIO_WG34)->EnableWindow(false);	
	GetDlgItem(IDC_RADIO_WG26)->EnableWindow(false);	

}
